Read the txt and return it all in a Java String

Asked

Viewed 444 times

2

I have this code to read one txtand would like to return later a string with the txtall copied , but this algorithm it just read the lines and goes showing how to return all the content it read in a variable string?

  public static void main (String[]args){
      String linha = null;

      try{
         BufferedReader br = new BufferedReader(new FileReader("c:/algoritmo.txt"));
         while(br.ready()){
             linha= br.readLine();
            System.out.println(linha);

         }
         br.close();
      }catch(IOException ioe){
         ioe.printStackTrace();

      }
      System.out.println());}
}

1 answer

3


Browser other questions tagged

You are not signed in. Login or sign up in order to post.