Advertisement
Guest User

ReadData

a guest
Jul 19th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package datastorage;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6.  
  7. public class ReadData {
  8.        
  9.     public static void readData() {
  10.    
  11.     int n = 0;
  12.     SolidStateDrive[] ssd = new SolidStateDrive[n+1];
  13.    
  14.         try  {
  15.             BufferedReader br = new BufferedReader(new FileReader("SSD.txt"));
  16.             String line = null;
  17.  
  18.             while((line = br.readLine()) != null) {
  19.                     String tmp[] = line.split("\t");
  20.                     ssd[n] = new SolidStateDrive();
  21.                     ssd[n].brand = tmp[0];
  22.                     ssd[n].model = tmp[1];
  23.                     ssd[n].capacityInGB = Integer.parseInt(tmp[2]);
  24.                 n++;
  25.             }
  26.            
  27.             br.close();
  28.             for (int j=0; j<=n; j++) {
  29.                 System.out.println(j+ "\t" +ssd[j].brand+ "\t" +ssd[j].model+ "\t" +ssd[j].capacityInGB);
  30.             }
  31.            
  32.         } catch(IOException ex) {
  33.             ex.printStackTrace();
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement