应用私有目录下进行文件的读写操作

时间:2021-09-29 19:57:21
@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    BufferedWriter writer ;
    try {
        String path = getFilesDir().getAbsolutePath() ;
        File file = new File(path + "/etc") ;
        if(!file.exists()){
            file.mkdirs() ;
        }
        File file2 = new File(file.getAbsoluteFile() + "/name.txt") ;
        FileOutputStream out = new FileOutputStream(file2);
        writer = new BufferedWriter(new OutputStreamWriter(out)) ;
        try {
            writer.write("123123") ;
            writer.close() ;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}