写文件文件问题!

alemjann 2003-05-09 11:18:47
可以生成文件,但是文件没有内容,请大家指点!谢谢。
/************************************/

package fwrite;

import java.io.*;

public class FWriter {
public FWriter(String content) throws IOException
{
System.out.println(content);
String file_path = "file/";
String root = "d:/";
String file_name = "aaa.txt";
File file = new File(root + File.separator + file_path + File.separator + file_name);
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
pw.write(content);
}

public static void main(String[] args) {
try
{
FWriter fwr = new FWriter("hello file!");
}
catch(IOException ioe)
{
System.out.println(ioe.toString());
}
}
}
...全文
42 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lotofu 2003-05-09
  • 打赏
  • 举报
回复
pw.write(content);//之后,加上
pw.flush();
pw.close();

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧