reading tab delimited textfile java

前端 未结 2 573
别那么骄傲
别那么骄傲 2020-12-21 14:26
10
aaa aaa aaa
bbb bbb bbb
ccc ccc ccc
ffffd ffffd ffffd

I have a textfile that Im trying to read with tab delimiters. whenever i read the file, i get an

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-21 15:15

    This way your code loses this ugly break (break are most of the time avoidable ...)

      try{
        Scanner scan = new Scanner(new File("1.txt"));
        String line="";
        int readline = Integer.parseInt(scan.nextLine());//
    
        while (scan.hasNextLine())
        {
            line = scan.nextLine();
    
            if(!line.equals("aaa")){
               String[] split=line.split("\t");
               array.add(split);
            }
        }  
    

    And about your problem I think you are initializing your array with the integer on the first line but it is 10 and you have 12 elements. Thus the index out of bounds but your question remains unclear ...

提交回复
热议问题