麻烦请写下 示例 代码
String result;//要写入的内容
String file;//要写入的文件路径
public static void writeInTxt(String result,String file) throws Exception {文件后缀为。html不就行了。你又不是web项目,没用到http请求,要是用到的话,直接PrintWriter.println() 要写成html的用DOM4j或JDOM的xml方式去写要好
// TODO Auto-generated method stub
ifexist(file);
PrintWriter pw=new PrintWriter(new FileWriter(file));
pw.print(result);
pw.flush();
System.out.println("写入成功");
}
// 随便网上一找都有的..
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();
}
}
}