首先在应用程序中下载文件,并保留名称为try.pdf
这里的代码:
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();
}
当尝试使用 FileInputStream 读取文件“try.pdf”的文件时,我有错误 outOfMemory,有什么解决方案吗?
谢谢