0
特定のjsonファイルをダウンロードしてから、アプリケーションにテキストファイルとして保存する必要があります。は、アンドロイドのURLからすべての文字をダウンロードできません。
public void readAndStoreFile() throws Exception {
try {
URL url = new URL(address);
URLConnection con = url.openConnection();
int length = con.getContentLength();
if (length > 0) {
Log.i("lenght of bytes received", "" + length);
InputStream fis = con.getInputStream();
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader bf = new BufferedReader(isr);
String content = new String();
String line = null;
while ((line = bf.readLine()) != null) {
content += line;
}
FileOutputStream fos = c.openFileOutput(filename,
Context.MODE_PRIVATE);
BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(
fos));
bfw.write(content);
} else
throw new NegativeArraySizeException();
} catch (Exception e) {
throw e;
}
}
しかし、全体のJSONファイルは、テキストファイルにダウンロードされていない何らかの理由:このために私は次のコードを使用しています。ダウンロードと書き込みが停止したあと、一定数の文字のみがダウンロードされ、書き込まれます。なぜそれが起こっているのですか?私が使用しています
urlは
http://opisop.webuildapps.com/api/shops.jsonは、事前にあなたに感謝です。