0
点赞
收藏
分享

微信扫一扫

Java创建TXT文件并写入 内容

成义随笔 2022-06-03 阅读 55
public static void main(String[] args)
{
String filePath = "E:/" + "1.txt";
FileWriter fw = null;
try
{
File file = new File(filePath);
if (!file.exists())
{
file.createNewFile();
}
fw = new FileWriter(filePath);
BufferedWriter bw=new BufferedWriter(fw);
bw.write("hello\n");
bw.write("world\n");
bw.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
fw.close();
}
catch (Exception e)
{
e.printStackTrace();
}

}

}

 


举报

相关推荐

0 条评论