How To Create And Write In A Txt File Using Java NetBeans
In this Java Tutorial we will see How To Create A Text File In A Specific Path And Write Into It Using Java NetBeans .
Project Source Code:
private void jButton_CreateWriteActionPerformed(java.awt.event.ActionEvent evt) {
File file = new File("C:\\Users\\omar\\Desktop\\haha\\folder1\\myTextFile.txt");
if(!file.exists())
{
try {
file.createNewFile();
FileWriter fw = new FileWriter(file.getAbsolutePath());
BufferedWriter bw = new BufferedWriter(fw);
bw.write("My Text Here");
bw.close();
fw.close();
} catch (IOException ex) {
Logger.getLogger(CreateFileAndWrite.class.getName()).log(Level.SEVERE, null, ex);
}
}else{
System.out.println("File Already Exist");
}
}
Download Projects Source Code