public static void main(String[] args)
{
String filePath = "E:/" + "1.txt";
String content = "这是txt文件";
FileWriter fw = null;
try
{
File file = new File(filePath);
if (!file.exists())
{
file.createNewFile();
}
fw = new FileWriter(filePath);
fw.write(content);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
fw.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Java创建TXT文件并写入 内容
于 2021-06-03 11:27:00 首次发布