Posted By

mouseroot on 11/08/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nicc777


Read and Write to Files


 / Published in: Java
 

Read and write to files in java

  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. class ...
  5.  
  6. public static void main(String args[]) ...
  7.  
  8. try {
  9.  
  10. //Read
  11. Scanner FileI = new Scanner(new FileInputStream("C://path//to//file.ext"));
  12.  
  13. //Write
  14. Writer FileO = new OutputStreamWriter(new FileOutputStream("C://path//to.ext"));
  15.  
  16. //Read a line
  17.  
  18. FileI.nextLine();
  19.  
  20. //Write a line
  21.  
  22. FileO.write("");
  23.  
  24. } catch(IOException ee) {
  25. System.out.println("There was an error " + ee);
  26. }

Report this snippet  

You need to login to post a comment.