Java how to create and write to a file How to write to file in Java Reading Writing and Creating Files Write to file using a BufferedWriter Reading and writing text files using java.io package how to write two or more lines in java in file
import java.io.BufferedWriter;
import java.io.FileWriter;
import javax.swing.JOptionPane;
public class FileWriteExample {
public static void main(String[] args) {
try {
FileWriter fw = new FileWriter("Z:\\myFile.txt");
BufferedWriter bw = new BufferedWriter(fw);
String stringFile="First Line\n";
stringFile+="2nd Line";
bw.write(stringFile);
bw.close( );
JOptionPane.showMessageDialog(null, "File Sucessfully Create !");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Exception: "+e);
}
}
}
import java.io.BufferedWriter;
import java.io.FileWriter;
import javax.swing.JOptionPane;
public class FileWriteExample {
public static void main(String[] args) {
try {
FileWriter fw = new FileWriter("Z:\\myFile.txt");
BufferedWriter bw = new BufferedWriter(fw);
String stringFile="First Line\n";
stringFile+="2nd Line";
bw.write(stringFile);
bw.close( );
JOptionPane.showMessageDialog(null, "File Sucessfully Create !");
}
catch(Exception e){
JOptionPane.showMessageDialog(null, "Exception: "+e);
}
}
}
0 comments:
Post a Comment