我正在使用Android Studio中的某个应用,我在assets文件夹中有一个文件。虽然它没有路径,我需要从中创建File对象,但我已经编写了这段代码:
InputStream asset = assetManager.open("databases/file.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(asset));
StringBuilder sb = new StringBuilder();
String line, result;
while ((line = br.readLine()) != null) {
sb.append(line);
}
result = sb.toString();
byte[] resultToBytes = result.getBytes();
File file = new File(getExternalFilesDir(null).getAbsolutePath(),"tmp");
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(resultToBytes);
fileOutputStream.close();
当我将文件拉回计算机时,我发现它已损坏,或者只是与原始文件不同,也是大小。我什么时候出错?