Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package unisystem;
- import java.io.FileInputStream;
- import java.io.LineNumberInputStream;
- @SuppressWarnings("deprecation")
- public class DateiEinlesen {
- private int bufferSize = 15;
- private String filePath = "/Users/K.T.F/eclipse-workspace/unisystem/src/unisystem/Ergebnis";
- private byte buffer[] = new byte[bufferSize];
- private FileInputStream fis;
- private LineNumberInputStream lnis;
- // Constructor calls setInputStreams() to initialize input streams.
- public DateiEinlesen()
- {
- setInputStreams();
- readData();
- }
- /**
- * This method Initializes the input streams.
- */
- public void setInputStreams()
- {
- try {
- fis = new FileInputStream(filePath);
- lnis = new LineNumberInputStream(fis);
- } catch(Exception e){
- System.out.println("Error! Problem initializing input streams in method setInputStreams().");
- }
- }
- /**
- * This method calculates the number of lines in the file.
- */
- public int readNumberOfLines()
- {
- int lineNumber = 0;
- /**
- * We'll iterate through each byte in the file and determine the current
- * line number at every point and when a new line number is encountered we'll
- * update lineNumber.
- */
- try {
- while(lnis.read()!= -1)
- {
- if(lnis.getLineNumber() != lineNumber)
- {
- lineNumber = lnis.getLineNumber();
- }
- }
- } catch (Exception e) {
- System.out.println("Error! Can\'t read data from file in method readNumberOfLines().");
- }
- return lineNumber;
- }
- /**
- * This method reads the next data stream from the file.
- * Uses ';' as the delimiter.
- */
- public String readData()
- {
- int readByte;
- String data;
- try {
- int iterator = 0;
- while ((readByte = lnis.read()) != -1)
- {
- if(lnis.getLineNumber() == 0)
- {
- continue;
- }
- else if ((char)readByte != ';' && readByte != 10)
- {
- buffer[iterator] = (byte)readByte;
- } else {
- break;
- }
- iterator++;
- }
- } catch (Exception e) {
- System.out.println("Error! Can\'t read data from file in method readData()."+e);
- }
- data = new String(buffer);
- clearBuffer();
- return data;
- }
- public double[] readgesamtPunkte()
- {
- double gesamtPunkte[] = new double[9];
- for (int i = 0; i < 9; i++)
- {
- gesamtPunkte[i] = Double.parseDouble(readData());
- }
- return gesamtPunkte;
- }
- public void clearBuffer()
- {
- buffer = new byte[bufferSize];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment