Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to empty a file

Status
Not open for further replies.

cadbilbao

Programmer
Apr 9, 2001
233
ES
Hi!

I've got

FileWriter out = new FileWriter(outputFile);

I write on this 'out' file, but I want to empty it at one moment.

How can I do this?
 
import java.io.*;


public class FW
{
public static void main(String args[])
{
FileWriter out=null;
try
{
out = new FileWriter("c:/test.txt");
out.write("blah blah blah");
out.flush();
out.close();


//doing something..
//
//
//

//now emptying the file test.txt...
out = new FileWriter("c:/test.txt");
out.flush();
out.close();
}
catch(Exception e)
{
System.out.println("Exception:"+e);

}

}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top