Languages
[Edit]
EN

Java - read all text from file with custom FileUtils

11 points
Created by:
Root-ssh
178180

In this article, we would like to show how in Java, read all text from file to string.

Quick solution:

Example output:

Example input.txt:

Example input.txt file ready as text in Java.
Example input.txt file ready as text in Java.

 

This article presents some simple util that lets users to read file using: String path, File object, Path object, Reader object or InputStream object.

1. File reading example

Edit

Note: check below FileUtils.java file to see how text reading util looks.  

Program.java file:

2. Used file utils

Edit

FileUtils.java file:

3. Used input resources

Edit

input.txt file (full path is C:\Project\input.txt):

Merged questions

Edit
  1. Java - how to read all lines as one string from file object?
  2. Java - how to read all lines as one string from input stream object?
  3. Java - how to read all lines as one string from reader object?
  4. Java - how to read all lines as one string using file path string?
  5. Java - how to read all lines as one string using path object?

See also

Edit

Alternative titles

  1. Java - how to read all lines as one string from file object?
  2. Java - how to read all lines as one string from input stream object?
  3. Java - how to read all lines as one string from reader object?
  4. Java - how to read all lines as one string using file path string?
  5. Java - how to read all lines as one string using path object?
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join