サーバーに存在するファイルからテキストを読み込もうとしています。このファイルには「hello world」というテキストが含まれています。このテキストを TextView に書きたいと思います。必要なパッケージをすべてインポートしました。前もって感謝します
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
try {
URL updateURL = new URL("http://--------------------/foldername/hello.txt");
URLConnection conn = updateURL.openConnection();
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while((current = bis.read()) != -1){
baf.append((byte)current);
}
final String s = new String(baf.toByteArray());
((TextView)tv).setText(s);
} catch (Exception e) {
}
};