Topic: io问题(new PrintStream总把上次的数据清空)

  Print this page

1.io问题(new PrintStream总把上次的数据清空) Copy to clipboard
Posted by: joelwx
Posted on: 2005-07-09 10:12

目的:打开文件写数据,写入的数据就加在上次数据之后;
问题:总把上次的数据清空!!!
我用的输出流是PrintStream ps=new PrintStream(new FileOutputStream(file));
ps.println(data);

请教各位,如何实现我的目的???

2.Re:io问题 [Re: joelwx] Copy to clipboard
Posted by: bohui0714
Posted on: 2005-07-10 20:55

//PrintStream ps=new PrintStream(new FileOutputStream(file));
PrintStream ps=new PrintStream(new FileOutputStream(file,true));

FileOutputStream
public FileOutputStream(File file,
boolean append)
throws FileNotFoundException
Creates a file output stream to write to the file represented by the specified File object. 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 the path represented by the file argument 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:
file - the file to be opened for writing.
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:
1.4

3.Re:io问题 [Re: joelwx] Copy to clipboard
Posted by: joelwx
Posted on: 2005-07-11 08:19

谢谢!!!

4.Re:io问题 [Re: joelwx] Copy to clipboard
Posted by: Destroyer
Posted on: 2005-08-30 07:25

不会吧 这么长 好厉害哦!!

5.Re:io问题 [Re: joelwx] Copy to clipboard
Posted by: SUPLAD
Posted on: 2005-09-13 17:04

s1=br.readLine();有没有这样的用法,WHY会运行时会提示范区 . 这有问题

6.Re:io问题 [Re: SUPLAD] Copy to clipboard
Posted by: why
Posted on: 2005-09-13 23:50

SUPLAD wrote:
s1=br.readLine();有没有这样的用法,WHY会运行时会提示范区. 这有问题

Why did you ask such a question here?
What is 提示范区??

Yes, 有这样的用法, here s1 is a String and br is a BufferedReader, I think.
http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedReader.html#readLine()


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923