Advertisement
fursty

OOP Upr 7 File WiP

Mar 12th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. package Reader;
  2.  
  3. import java.io.RandomAccessFile;
  4. import java.io.IOException;
  5.  
  6. public class RAFReader implements Readerr{
  7.     private ColorRectangle[] rectangles  = new ColorRectangle[10];
  8.     public Object readFile(String fileName) {
  9.         try {
  10.             RandomAccessFile file = new RandomAccessFile(fileName, "r");
  11.             int i = 0;
  12.             String strLine;
  13.             String[] res = new String[5];
  14.             while((strLine = file.readLine()) != null) {
  15.                 res = strLine.split("  ");
  16.                 int x1 = Integer.parseInt(res[0]);
  17.                 int y1 = Integer.parseInt(res[1]);
  18.                 int x2 = Integer.parseInt(res[2]);
  19.                 int y2 = Integer.parseInt(res[3]);
  20.                 long c= Long.parseLong (res[4]);
  21.                 ColorRectangle a=new ColorRectangle(x1,y1,x2,y2,c);
  22.                 if (i==rectangles.lenght) break;
  23.                 rectangles[i++]=a;
  24.             }
  25.             file.close();
  26.         }
  27.        
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement