文件未完全写入 [英] File not being completely written

查看:64
本文介绍了文件未完全写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取Nexus 5上的系统文件,并将其进行一些修改后重写为第二个文件.问题是,即使不进行我的修改,文件也不会完全写入.Il快要结束了,然后总是在同一位置停止书写.停在第450行,仅在应该写入< path name ="voice-tty-full-headphones"> 并继续执行另外30时才写入<路径名行...

I'm trying to read a system file on the Nexus 5 and rewrite it to a second file with some modifications I will make. The problem is even without my modifications the file is not written completely. Il gets almost to the end and then stops writing always at the same place. Stops at line 450 and only writes <path name when it should write <path name="voice-tty-full-headphones"> and continue for 30 more lines...

奇怪的是,如果我导出到textview中的所有内容都存在,那么问题就不在读取文件时而是在写入新文件时.我附上了我正在使用的文件的副本以及正在生成的文件的副本.我真的不知道从这里尝试什么.

Strangely if I export to a textview everything is there so the problem is not when reading the file but when writing to the new one. I have attached a copy of the file i'm working with along with a copy of the file thats being generated. I really have no idea what to try from here.

//Output File
File outputFile = new File(Environment.getExternalStorageDirectory().getPath(), "/xxx/mixer_paths.xml");
outputFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(outputFile);
OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut);

//Input File
File internalStorage = Environment.getRootDirectory();
File inputFile = new File(internalStorage,"/etc/mixer_paths.xml");
BufferedReader br = new BufferedReader(new FileReader(inputFile));

StringBuilder text = new StringBuilder();
String line;


while ((line = br.readLine()) != null )
{
    text.append(line+"\n");
}

    myOutWriter.append(text);
    textView.setText(text);

https://www.dropbox.com/s/7p1cgu7ziyzydh1/mixer_paths_original.xml https://www.dropbox.com/s/zs03xt4k52vetek/mixer_paths_new.xml

谢谢

推荐答案

您忘记关闭编写器了吗?我自己犯了这个错误.处理完读者和作家后,请务必关闭他们.这样可以释放资源,并且对于编写者来说,请确保完成编写!

Did you forget to close the writer? I've made this mistake myself. Always close your readers and writers when you are done with them. It frees up the resources and in the case of the writer, makes sure to finish writing!

这篇关于文件未完全写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆