Creating objects via txt file into an array in Java

后端 未结 3 1883
余生分开走
余生分开走 2021-01-24 21:23

I am trying to complete a little program.

I\'ve got a text file (.txt) to store different data on objects that i\'ve got.

The structure of the file is the next (

3条回答
  •  Happy的楠姐
    2021-01-24 21:40

    LineNumberReader  lnr = new LineNumberReader(new FileReader(new File("File1")));
    lnr.skip(Long.MAX_VALUE);
    
    long length = lnr.getLineNumber();
    
    lnr.close();
    
    in = new BufferedReader(new FileReader( "data.txt" ));
    
    Car[] cars= new Car[length/5];
    String currentLine;
    int i=0;
    
    for(int i=0;i

    You'll have to handle exceptions too, surround stuff in try catch structures.

提交回复
热议问题