Easy way do it is using the FileWriter...
make sure that the file is not readprotected...
You can create the filewriter like:
FileWriter fw = new FileWriter(fileName, true);
if you want to add (append) more text in the file...
import java.io.*;
public class ClearFile {
public ClearFile(String fileName) {
try{
FileWriter fw = new FileWriter(fileName);
fw.write("");
}catch( IOException io) { io.printStackTrace(); }
}
public static void main(String[] args) {
ClearFile clear = new ClearFile("D:\\hello.txt");
}
}
I hope it solve your problem!