1.创建文件写入数据方法
public void writeSDFile(String fileName, String write_str) throws IOException{
File file = new File(fileName);
FileOutputStream fos = new FileOutputStream(file);
byte [] bytes = write_str.getBytes();
fos.write(bytes);
fos.close();
}
1.1在需要的地方使用
writeSDFile(""文件路径和名字.txt"","需要写入的数据");
2.读取指定文件内容
直接复制工具类即可
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
/**
* Created by cruze on 2015/7/29.
*/
public class TxtTool {
public static String readTxt(String path){
String str = "";
try {
File urlFile = new File(path);
InputStreamReader isr = new InputStreamReader(new FileInputStream(urlFile), "UTF-8");
BufferedReader br = new BufferedReader(isr);
String mimeTypeLine = null ;
while ((mimeTypeLine = br.readLine()) != null) {
str = str+mimeTypeLine;
}
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
2.1在需要的地方调用
String image_versions = TxtTool.readTxt("路径和名字.txt");
|