如何将数据保存到Java中的文件? [英] How to save the data into File in java?
本文介绍了如何将数据保存到Java中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
感谢,
vara kumar.pjd
解决方案
使用de文件名中的时间戳记,以确保它是唯一的。 *;
class FileWrite
{
public static void main(String args [])
{
try {
//创建文件
FileWriter fstream = new FileWriter(System.currentTimeMillis()+out.txt);
BufferedWriter out = new BufferedWriter(fstream);
out.write(Hello Java);
//关闭输出流
out.close();
} catch(Exception e){//捕获异常,如果有
System.err.println(Error:+ e.getMessage());
这是非常很容易google。
I have one problem, that is I have one string of data and I want to save it into a separate file every time. Please give me a suggestion.
Thanks, vara kumar.pjd
解决方案
Use a timestamp in de filename so you can be sure it is unique.
import java.io.*;
class FileWrite
{
public static void main(String args[])
{
try{
// Create file
FileWriter fstream = new FileWriter(System.currentTimeMillis() + "out.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Hello Java");
//Close the output stream
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
This is something that is very easy to google.
这篇关于如何将数据保存到Java中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文