About 317,000 results
Open links in new tab
  1. How do I create a Java string from the contents of a file?

    Read all text from a file. Java 11 added the readString() method to read small files as a String, preserving line terminators:

  2. How to read a file into string in java? - Stack Overflow

    May 25, 2013 · I have read a file into a String. The file contains various names, one name per line. Now the problem is that I want those names in a String array. For that I have written the following code: String [] names = fileString.split("\n"); // fileString is the string representation of the file

  3. Reading a plain text file in Java - Stack Overflow

    I documented 15 ways to read a file in Java and then tested them for speed with various file sizes - from 1 KB to 1 GB and here are the top three ways to do this: java.nio.file.Files.readAllBytes() Tested to work in Java 7, 8, and 9.

  4. Whole text file to a String in Java - Stack Overflow

    Oct 3, 2010 · I documented 15 ways to read from a file in Java and these are from that article. Note that you still have to loop through the list that's returned, even though the actual call to read the contents of the file requires just 1 line, without looping. 1) java.nio.file.Files.readAllLines() - Default Encoding

  5. Java 8: Reading a file into a String - Stack Overflow

    Jul 24, 2019 · But it must be emphasized that the String(byte[]) constructor will use the system’s default encoding which surely isn’t the right choice for a resource embedded in a Java application. The application should be explicit regarding the resource’s encoding.

  6. read complete file without using loop in java - Stack Overflow

    Jan 5, 2013 · How to create a Java String from the contents of a file Whole text file to a String in Java. I am trying to read the contents of a file using FileReader . But i want to read the file without reading a line by line . Is it possible to read the whole file without loop. I …

  7. Java reading a file into an ArrayList? - Stack Overflow

    May 21, 2022 · How do you read the contents of a file into an ArrayList<String> in Java? Here are the file contents: cat house dog . . .

  8. Read resource text file to String in Java - Stack Overflow

    While I've used this, I completely disagree on avoiding 3rd party packages. The fact that in Java, the only way to easily read a file to string is with the scanner trick is pretty sad. The alternative to using a 3rd party lib is that everyone will just create their own wrappers.

  9. Reading a .txt file using Scanner class in Java - Stack Overflow

    I am working on a Java program that reads a text file line-by-line, each with a number, takes each number throws it into an array, then tries and use insertion sort to sort the array. I need help w...

  10. java - What is simplest way to read a file into String ... - Stack …

    Aug 4, 2010 · String toString(File, Charset) Using the given character set, reads all characters from a file into a String; List<String> readLines(File, Charset)... reads all of the lines from a file into a List<String>, one entry per line; Apache Commons/IO. org.apache.commons.io.IOUtils also offer similar functionality: String toString(InputStream, String ...

Refresh