/**
* Use FileWriter to write an array of storage to a file.
*/
package FileIO;
import java.io.*;
/**
* @author Administrator
*
*/
public class WriteChars {
/**
* @param args
*/
public static void main(String[] args) {
FileWriter fw;
String strs[] = { "32435 Tom@HerbSchildt.com",
"86754 Mary@HerbSchildt.com",
"35789 TC@HerbSchildt.com" };
try {
// Open the output file.
fw = new FileWriter("Employees.data");
} catch (IOException exc) {
System.out.println("Error Opening File");
return ;
}
try {
// Write the strings in strs to the file.
for (int i = 0; i < strs.length; ++i) {
fw.write(strs[i]); // write a line to file
fw.write("\n"); // output a newline
}
} catch (IOException exc) {
System.out.println("Error Writing File");
}
try {
fw.close();
} catch (IOException exc) {
System.out.println("Error Closing File");
}
}
}
WriteChars
最新推荐文章于 2023-04-16 18:06:29 发布