Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.text.*;
- public class ReadFromFile {
- String cont="yes";
- String accRead[];
- int counter=0;
- int count=0;
- String fc = "";
- //returns a String that holds the content of the data saved to the file
- public String readFromFile(String fileName){
- try{ //need this - equivalent to throws IOException
- BufferedReader fh = new BufferedReader(new FileReader(fileName));//opens the file
- String s;//this will be equal to a line in the text file
- while ((s=fh.readLine())!=null){ //loops keeps going until there are no more lines to read
- fc += s
- }//end of while
- fh.close(); //close the file
- } catch (Exception e){ //if there was an error in accessing the file this would catch it.
- System.out.println("There was an error");
- }
- return fc;
- }//end of readFromFile Method
- }//end of class
Add Comment
Please, Sign In to add comment