Android - Read Only File System IOException

前端 未结 2 1128
时光说笑
时光说笑 2020-12-03 05:11

I am trying to write to a simple text file on the Android system. This is my code:

public void writeClassName() throws IOException{
    String FILENAME = \"c         


        
相关标签:
2条回答
  • 2020-12-03 05:57

    Try to use the approach from this article in developer guide:

    String FILENAME = "hello_file";
    String string = "hello world!";
    
    FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
    fos.write(string.getBytes());
    fos.close();
    
    0 讨论(0)
  • 2020-12-03 06:01

    Because you are trying to write the file to root, you need to pass the file path to your file directory.

    Example

    String filePath = context.getFilesDir().getPath().toString() + "/fileName.txt";
    File f = new File(filePath);
    
    0 讨论(0)
提交回复
热议问题