直接上代码~
注意权限
1.写入数据
private void writeData() {
String filePath = "/sdcard/Gyt/";
String fileName = "data.txt";
writeTxtToFile("Wx:lcti1314", filePath, fileName);
}
// 将字符串写入到文本文件中
private void writeTxtToFile(String strcontent, String filePath, String fileName) {
//生成文件夹之后,再生成文件,不然会出错
makeFilePath(filePath, fileName);
String strFilePath = filePath + fileName;
// 每次写入时,都换行写
String strContent = strcontent + "\r\n";
try {
File file = new File(strFilePath);
if (!file.exists()) {
Log.d("TestFile", "Create the file:" + strFilePath);
file.getParentFile().mkdirs();
file.createNewFile();
}
RandomAccessFile raf = new RandomAccessFile(