BufferedReader: read multiple lines into a single string

后端 未结 7 1108
逝去的感伤
逝去的感伤 2021-01-17 11:22

I\'m reading numbers from a txt file using BufferedReader for analysis. The way I\'m going about this now is- reading a line using .readline, splitting this string into an a

7条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 11:47

    This creates a long string, every line is seprateted from string " " (one space):

    public String ReadBigStringIn() {
        StringBuffer line = new StringBuffer();
    
    
        try { 
            while(buffIn.ready()) {
            line.append(" " + buffIn.readLine());
        } catch(IOException e){
            e.printStackTrace();
        }
    
        return line.toString();
    }
    

提交回复
热议问题