首先下載應用程序文件,並與該名try.pdf的OutOfMemoryError中的FileInputStream
代碼在這裏留着,
try {
URL url = new URL(aurl[0]);
URLConnection conexion = url.openConnection();
conexion.connect();
int lenghtOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
InputStream input = new BufferedInputStream(url.openStream());
FileOutputStream fos = openFileOutput("try.pdf", Context.MODE_PRIVATE);
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
publishProgress(""+(int)((total*100)/lenghtOfFile));
fos.write(data, 0, count);
}
fos.flush();
fos.close();
input.close();
} catch (Exception e) {}
return null;
}
現在,問題是當我想用打開它下面的代碼:
try {
FileInputStream in = openFileInput("try.pdf");
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder sb = new StringBuilder();
String line;
try {
while ((line = bufferedReader.readLine()) != null){
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
當嘗試讀取文件「try.pdf」文件用的FileInputStream我有錯誤內存不足,任何解決方案?
Thanksss
PDF不是一個文本文件,你不應該像這樣處理它(用線閱讀並把它放到'StringBuilder'中) –
我在這裏沒有任何可疑的部分,你能給出額外的細節嗎? – 18bytes
我在webView中顯示該文件? – jlopez