Guest User

Untitled

a guest
Jan 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. // Demonstrate FileWriter.
  2. import java.io.*;
  3. class FileWriterDemo {
  4. public static void main(String args[]) throws Exception {
  5. String source = "Now is the time for all good men\\n"
  6. + " to come to the aid of their country\\n"
  7. + " and pay their due taxes.";
  8. char buffer[] = new char[source.length()];
  9. source.getChars(0, source.length(), buffer, 0);
  10. FileWriter f0 = new FileWriter("file1.txt");
  11. for (int i=0; i < buffer.length; i += 2) {
  12. f0.write(buffer[i]);
  13. }
  14. f0.close();
  15. FileWriter f1 = new FileWriter("file2.txt");
  16. f1.write(buffer);
  17. f1.close();
  18. FileWriter f2 = new FileWriter("file3.txt");
  19. f2.write(buffer,buffer.lengthbuffer.
  20. length/4,buffer.length/4);
  21. f2.close();
  22. }
  23. }
Add Comment
Please, Sign In to add comment