2016-08-19 135 views
0

我有一个帮助类,我需要为我的应用程序处理数据。如何使用opencsv写入Android内部存储中的文件?

我已经设置它,所以它从URL读取文件。阅读本身的作品,但我很难写这个文件到应用程序的内部存储。

根据Android教程我已经使用FileOutputStream来编写文件。但是,我发现很难找到解决方案来编写FileOutputStream并使用CSVWriter构造函数解决它。

的代码是很长,所以我将发布一个要点,如果你需要什么我的代码做更多的信息,但在这里,这是造成我的问题位:

BufferedReader in = new BufferedReader(new InputStreamReader(file_url.openStream())); 
      String test; 
      CSVReader reader = new CSVReader(in, ';'); 
      FileOutputStream file_out = app_context.openFileOutput(file_name, Context.MODE_PRIVATE); 
      CSVWriter writer = new CSVWriter(<What goes here?>, ';'); 

https://gist.github.com/anonymous/4cde37a8614d1c69cc03ec678d36a9d7

异常抛出与CSVWriter作家=新CSVWriter(将String.valueOf(file_out), ';');:

08-19 14:22:30.794 29439-30099/com.example.a1003137m.profitgraph W/System.err: java.io.FileNotFoundException: [email protected]: open failed: EROFS (Read-only file system) 
08-19 14:22:30.794 29439-30099/com.example.a1003137m.profitgraph W/System.err:  at libcore.io.IoBridge.open(IoBridge.java:452) 
08-19 14:22:30.794 29439-30099/com.example.a1003137m.profitgraph W/System.err:  at java.io.FileOutputStream.<init>(FileOutputStream.java:87) 
08-19 14:22:30.794 29439-30099/com.example.a1003137m.profitgraph W/System.err:  at java.io.FileOutputStream.<init>(FileOutputStream.java:72) 
08-19 14:22:30.794 29439-30099/com.example.a1003137m.profitgraph W/System.err:  at java.io.FileWriter.<init>(FileWriter.java:80) 
08-19 14:22:30.794 29439-30099/com.example.a1003137m.profitgraph W/System.err:  at com.example.a1003137m.profitgraph.FileProcessor.processFile(FileProcessor.java:50) 
08-19 14:22:30.794 29439-30099/com.example.a1003137m.profitgraph W/System.err:  at com.example.a1003137m.profitgraph.FileProcessor.run(FileProcessor.java:40) 
08-19 14:22:30.795 29439-30099/com.example.a1003137m.profitgraph W/System.err: Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system) 
08-19 14:22:30.795 29439-30099/com.example.a1003137m.profitgraph W/System.err:  at libcore.io.Posix.open(Native Method) 
08-19 14:22:30.795 29439-30099/com.example.a1003137m.profitgraph W/System.err:  at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) 
08-19 14:22:30.795 29439-30099/com.example.a1003137m.profitgraph W/System.err:  at libcore.io.IoBridge.open(IoBridge.java:438) 
08-19 14:22:30.795 29439-30099/com.example.a1003137m.profitgraph W/System.err: ... 5 more 
+0

'<这里有什么?>'。你尝试过'file_out'吗? – greenapps

+0

是的,它告诉我用String.valueOf()包装它,但它会抛出异常。 – cmackie21

+0

你不会告诉哪一个?不聪明!发布logcat。 – greenapps

回答

1

new CSVReader(in, ';');现在inInputStream。那么你会用new CSVWriter(out, ';');什么?事实上:一个OutputStream!另外对于您使用BufferedReaderInputStreamReader的读者。

所以做类似的事情:BufferedWriterOutputStreamWriter

相关问题