文件写入
//文件写入的位置为./data/data/包名/files/文件名 public void fileW(String message) { try { FileOutputStream fout = MainActivity.this.openFileOutput(“a.txt”, MODE_PRIVATE); byte[] bytes = message.getBytes(); fout.write(bytes); fout.close(); } catch (Exception e) { e.printStackTrace(); } }
文件读取
public String fileR(){ String res = ""; try { FileInputStream fin = new FileInputStream("./data/data/com.example.filewr/files/a.txt"); int length = fin.available(); byte[] buffer = new byte[length]; fin.read(buffer); res = EncodingUtils.getString(buffer, "UTF-8"); fin.close();//关闭资源 } catch (Exception e) { e.printStackTrace(); } return res; }