import java.io.*;
public class FileWriterDemo {
/**
* @param args
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String source = "Now is the time for all good men\n" +
" to come to aid of their country\n" +
" and pay their due taxes";
char buffer[] = new char[source.length()];
source.getChars(0, source.length(), buffer, 0);
FileWriter f0 = new FileWriter("file1.txt");
FileWriter f1 = new FileWriter("file2.txt");
FileWriter f2 = new FileWriter("file3.txt");
try{
for(int i =0; i<buffer.length; i+=2){
f0.write(buffer[i]);
}
f1.write(buffer);
f2.write(buffer, buffer.length-buffer.length/4, buffer.length/4);
}catch (IOException e){
System.out.println("An I/O Error occured.");
}
}
}
这是我写的程序。我完全从一本书中复制了这个程序,但我的 IDE (Eclipse) 不断给我消息。当我尝试使用 FileOutputStream 类对象创建文件并写入文件时,也会遇到同样的问题。
这是一张图片