Store text file content line by line into array

后端 未结 11 1363
梦毁少年i
梦毁少年i 2020-12-05 12:09

all,I\'m now facing the problem of no idea on storing the content in text file into the array. The situation is like, text file content:

abc1
xyz2
rxy3
         


        
11条回答
  •  爱一瞬间的悲伤
    2020-12-05 12:31

    You can use this full code for your problem. For more details you can check it on appucoder.com

    class FileDemoTwo{
        public static void main(String args[])throws Exception{
            FileDemoTwo ob = new FileDemoTwo();
            BufferedReader in = new BufferedReader(new FileReader("read.txt"));
            String str;
            List list = new ArrayList();
            while((str =in.readLine()) != null ){
                list.add(str);
            }
            String[] stringArr = list.toArray(new String[0]);
            System.out.println(" "+Arrays.toString(stringArr)); 
        }
    
    }
    

提交回复
热议问题