Read and Write to Files


/ Published in: Java
Save to your folder(s)

Read and write to files in java


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.