Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package productorder;
- import java.io.IOException;
- import java.io.FileReader;
- import java.io.BufferedReader;
- public class ReadFile {
- private String path;
- public ReadFile(String text_path)
- {
- path = text_path;
- }
- public Products[] openFileProducts() throws IOException {
- FileReader new_reader = new FileReader(path);
- BufferedReader bfBufferedReader = new BufferedReader(new_reader);
- int size = countLines();
- String aLine;
- Products[] arrStrings = new Products[size];
- for (int i = 0; i < size; i++) {
- String temp = bfBufferedReader.readLine();
- String[] splitter = temp.split("\\s+");
- arrStrings[i] = new Products(splitter[0], Double.parseDouble(splitter[1]));
- }
- bfBufferedReader.close();
- return arrStrings;
- }
- public Orders[] OpenFileOrders() throws IOException {
- FileReader new_reader = new FileReader(path);
- BufferedReader bfBufferedReader = new BufferedReader(new_reader);
- int size = countLines();
- String aLine;
- Orders[] arrStrings = new Orders[size];
- for (int i = 0; i < size; i++) {
- String temp = bfBufferedReader.readLine();
- String[] splitter = temp.split("\\s+");
- arrStrings[i] = new Orders(Double.parseDouble(splitter[0]), splitter[1]);
- }
- bfBufferedReader.close();
- return arrStrings;
- }
- int countLines() throws IOException{
- FileReader new_read = new FileReader(path);
- BufferedReader new_bf = new BufferedReader(new_read);
- String aNewLineString;
- int counter = 0;
- while ((aNewLineString = new_bf.readLine()) != null) {
- counter++;
- }
- new_bf.close();
- return counter;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement