Skip to main content
added 73 characters in body
Source Link
Rajeev Sampath
  • 2.8k
  • 1
  • 18
  • 19

There's no single method that will read the entire file in java.io package, but you can quite easily do it by using a BufferedReader, reading line by line and appending them together with '\n' to get the full content. eg:

String line = null; StringBuilder sb = new StringBuilder(""); BufferedReader br = new BufferedReader("c:/path/yourfile.txt"); while ((thisLineline = br.readLine()) != null) { sb.append(line).append("\n"); } // you may probably need to remove the last '\n' before toString()  String fileContent = sb.toString(); 

There's no single method that will read the entire file, but you can quite easily do it by using a BufferedReader, reading line by line and appending them together with '\n' to get the full content. eg:

String line = null; StringBuilder sb = new StringBuilder(""); BufferedReader br = new BufferedReader("c:/path/yourfile.txt"); while ((thisLine = br.readLine()) != null) { sb.append(line).append("\n"); } String fileContent = sb.toString(); 

There's no single method that will read the entire file in java.io package, but you can quite easily do it by using a BufferedReader, reading line by line and appending them together with '\n' to get the full content. eg:

String line = null; StringBuilder sb = new StringBuilder(""); BufferedReader br = new BufferedReader("c:/path/yourfile.txt"); while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } // you may probably need to remove the last '\n' before toString()  String fileContent = sb.toString(); 
Source Link
Rajeev Sampath
  • 2.8k
  • 1
  • 18
  • 19

There's no single method that will read the entire file, but you can quite easily do it by using a BufferedReader, reading line by line and appending them together with '\n' to get the full content. eg:

String line = null; StringBuilder sb = new StringBuilder(""); BufferedReader br = new BufferedReader("c:/path/yourfile.txt"); while ((thisLine = br.readLine()) != null) { sb.append(line).append("\n"); } String fileContent = sb.toString();