Android 文件读写到命名空间的文件夹(简单)

来源:互联网 发布:linux 没有tmp文件夹 编辑:程序博客网 时间:2024/06/08 16:58
         文件保存到命名空间的files文件夹里
      FileOutputStream fileOutputStream ;try {fileOutputStream = getApplicationContext().openFileOutput(filename, MODE_WORLD_READABLE + MODE_WORLD_WRITEABLE);fileOutputStream.write(filecontent.getBytes());fileOutputStream.close();                                                                                                                                } catch (Exception e) {<span style="white-space:pre"></span>// TODO Auto-generated catch block<span style="white-space:pre"></span>e.printStackTrace();<span style="white-space:pre"></span>}

      从命名空间里的files文件夹里读取文件


     

              String path = getApplicationContext().getFilesDir().getAbsolutePath();filename = name.getText().toString();path = path +"/" +filename;File file = new File(path);FileInputStream fileInputStream;try {fileInputStream = new FileInputStream(file);byte[] buffer = new byte[1024];fileInputStream.read(buffer);fileInputStream.close();String neirong = new String(buffer, "utf-8");  //内容} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}

0 0