Java programming.
Write a public Java class called WriteToFile that opens a file called words.dat which is empty. Your program should read a String array called words and write each word onto a new line in the file. Your method should include an appropriate throws clause and should be defined within a class called TextFileEditor.
The string should
contain the following words:
{“the”, “quick”, “brown”, “fox”}
import java.io.FileWriter;
import java.io.PrintWriter;
public class WriteFile {
public static void main(String[] args) throws Exception {
String arr[] = { "the", "quick", "brown", "fox" };
writeFunction(arr);
}
private static void writeFunction(String[] arr) throws Exception {
PrintWriter pw = new PrintWriter(new FileWriter("words.dat"));
for (String s : arr) {
pw.println(s);
}
pw.close();
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME
Get Answers For Free
Most questions answered within 1 hours.