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.");
}
}
}
This is the program that I’ve written. I copied this program exactly from a book, but my IDE (Eclipse) keeps giving me message. This same problem is encountered when I try to use FileOutputStream class object to create a file and write to it.
Here’s an image
It just means the program completed, and in your case probably sucesfully, since it didnt print anything on console.
Just check the contents of
file1.txt , file2.txt and file3.txtto see if the program was successful