/**
* 写入
* @param filePath
* @param text
* @throws IOException
*/
public static void writeFile(String filePath,String text) throws IOException{
File file = new File(filePath);
FileWriter fw;
if (!file.exists()) {
file.createNewFile();
}
fw = new FileWriter(filePath);
fw.write(text);
fw.close();
}
/**
* 读取
* @param filePath
* @throws IOException
*/
public static void readFile(String filePath) throws IOException{
String encoding="GBK";
File file=new File(filePath);
if(file.isFile() && file.exists()){
InputStreamReader read = new InputStreamReader(
new FileInputStream(file),encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
while((lineTxt = bufferedReader.readLine()) != null){
System.out.println(lineTxt);
}
read.close();
}else{
System.out.println("找不到指定的文件");
}
}