Java read file and store text in an array

前端 未结 7 1871
心在旅途
心在旅途 2020-11-30 06:25

I know how to read a file with Java using Scanner and File IOException, but the only thing I don\'t know is how to store the text in the files as a

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 06:49

    I have found this way of reading strings from files to work best for me

    String st, full;
    full="";
    BufferedReader br = new BufferedReader(new FileReader(URL));
    while ((st=br.readLine())!=null) {
        full+=st;
    }
    

    "full" will be the completed combination of all of the lines. If you want to add a line break between the lines of text you would do full+=st+"\n";

提交回复
热议问题