日期:2014-05-20 浏览次数:20726 次
// 随便网上一找都有的..
public class JavaFileIO {
public static void main(String[] args) {
try {
String content = "this is text content..";
File file = new File("myfile2.txt");
if(!file.exists()){
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getName());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
System.out.println("Done.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void writeInTxt(String result,String file) throws Exception {
// TODO Auto-generated method stub
ifexist(file);
PrintWriter pw=new PrintWriter(new FileWriter(file));
pw.print(result);
pw.flush();
System.out.println("写入成功");
}