infinitetundra
2/3/2019 - 3:49 AM

FileReader

public class ReadFile {
	
private String path;

public ReadFile(String file_path) {
	path = file_path;
}
public String[] OpenFile() throws IOException{
	FileReader fr = new FileReader(path);
	BufferedReader txtReader = new BufferedReader(fr);
	int noOfLines = readLines();
	String[] txtData = new String[noOfLines];
	for(int i = 0 ; i < noOfLines; i++) {
		txtData[i] = txtReader.readLine();
	}
	txtReader.close();
	return txtData;
			
}
int readLines() throws IOException{
	FileReader file_to_read = new FileReader(path);
	BufferedReader bf = new BufferedReader(file_to_read);
	
	String aLine;
	int numberOfLines = 0;
	
	while((aLine = bf.readLine()) != null) {
	numberOfLines++;
	}
	bf.close();
	return numberOfLines;
	}

}