Guest User

Untitled

a guest
Jun 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.text.*;
  4.  
  5. public class ReadFromFile {
  6.  
  7. String cont="yes";
  8. String accRead[];
  9. int counter=0;
  10. int count=0;
  11. String fc = "";
  12.  
  13. //returns a String that holds the content of the data saved to the file
  14. public String readFromFile(String fileName){
  15.  
  16. try{ //need this - equivalent to throws IOException
  17. BufferedReader fh = new BufferedReader(new FileReader(fileName));//opens the file
  18. String s;//this will be equal to a line in the text file
  19.  
  20.  
  21.  
  22. while ((s=fh.readLine())!=null){ //loops keeps going until there are no more lines to read
  23.  
  24.  
  25. fc += s
  26.  
  27. }//end of while
  28.  
  29. fh.close(); //close the file
  30.  
  31.  
  32.  
  33. } catch (Exception e){ //if there was an error in accessing the file this would catch it.
  34. System.out.println("There was an error");
  35. }
  36. return fc;
  37. }//end of readFromFile Method
  38.  
  39. }//end of class
Add Comment
Please, Sign In to add comment