import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class WriteTextToAFile {
private static FileWriter fileWriter;
private static BufferedWriter bufferedWriter;
public static void main(String[] args) {
try {
fileWriter = new FileWriter("temp.txt");
bufferedWriter = new BufferedWriter(fileWriter);
bufferedWriter.write("Hello world!");
bufferedWriter.close();
System.out.println("File write is successful.");
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
fileWriter.close();
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}//End main method
No comments:
Post a Comment