我现在想向一个文件中添加内容,每次添加一行,我现在的做法如下:
FileWriter fileWriter = new FileWriter(new File(logPath));
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write("HelloYG"); bufferedWriter.newLine(); bufferedWriter.close();
但是这样写入之后,第二次启动程序并且运行的时候,上次写的内容就会丢失,请教各位我应该
如何保持住每次写入的内容,就是说每次只是添加内容!
FileWriter fileWriter = new FileWriter(new File(logPath));
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write("HelloYG"); bufferedWriter.newLine(); bufferedWriter.close();
但是这样写入之后,第二次启动程序并且运行的时候,上次写的内容就会丢失,请教各位我应该
如何保持住每次写入的内容,就是说每次只是添加内容!
解决方案 »
- java.net.ConnectException: Connection timed out: connect
- for语句中的一个冒号什么意思
- 如何在java中使用google map的api
- 谁能帮我分析一下这道题,头好痛。
- 急!!!java串口通讯问题,“CommPortIdentifier.getPortIdentifiers()取得端口列表为空”的问题。
- JTextField状态问题
- java 阻塞式socket+多任务处理
- servlet和applet实现的参数传递问题?求高手帮忙!
- 我装了1.4版本的怎么样把它删掉呀
- 在Java中有没有类似VB的MDI窗体?即:只有一个父窗体,里面可以容纳许多子窗体。
- Java连接SQLServer数据库,其中某表有两个字段是datetime类型的,请问如果在java的类中插入一条记录时时,datetiem型的字段该怎么处理?
- 同样的程序,为什么这个就编译不过去?
就可以了
public FileOutputStream(String name,
boolean append)
throws FileNotFoundExceptionCreates an output file stream to write to the file with the specified name. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection.
First, if there is a security manager, its checkWrite method is called with name as its argument. If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.
Parameters:
name - the system-dependent file name
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.
SecurityException - if a security manager exists and its checkWrite method denies write access to the file.
Since:
JDK1.1
See Also:
SecurityManager.checkWrite(java.lang.String)