重複の可能性:
サーバーからテキストを読み取っていない
サーバーに存在する .txt ファイルからテキストを読み取ろうとしていますが、私のコードはファイルからテキストを読み取っていません Android バージョン 2.1 を使用しています。また、エラーをキャッチするために例外を処理する方法を教えてください。 .
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv= new TextView(this);
StringBuilder content = new StringBuilder();
try {
URL url = new URL("http://linktomywebsite/textfile.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
content.append(str +"\n");
tv.setText(content);
}
in.close();
} catch (MalformedURLException e){
} catch (IOException e) {
e.printStackTrace();
}
};