The Files.readAllLines(path) already uses UTF-8 (see the linked documentation). If you're using the Files.readAllLines(path, charset) variant, well, pass UTF-8 as the charset, of course (for example by using StandardCharsets.UTF_8).

Assuming you're using either the short version or passing UTF-8, then the error lies not with java, but with your setup.

Either the file doesn't contain ≤ in UTF-8, or you're printing it in java to a place that doesn't show such symbols (for example, because your font doesn't have it, and uses ? as the placeholder symbol for 'I do not have this symbol in my font file'; it's more usually a box symbol), or you're sending the output someplace that incorrectly presumes that what is sent is not UTF-8.

Answer from rzwitserloot on Stack Overflow
🌐
Medium
medium.com › @AlexanderObregon › javas-files-readalllines-method-explained-14312314c1c4
Java’s Files.readAllLines() Method Explained | Medium
July 27, 2024 - The Files.readAllLines() method works by reading the entire content of a file into memory and splitting it into lines based on the line terminators (such as \n for Unix-based systems or \r\n for Windows).
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › file › Files.html
Files (Java Platform SE 8 )
April 21, 2026 - Tests whether a file is readable. This method checks that a file exists and that this Java virtual machine has appropriate privileges that would allow it open the file for reading. Depending on the implementation, this method may require to read file permissions, access control lists, or other ...
🌐
CodeSignal
codesignal.com › learn › courses › fundamentals-of-text-data-manipulation-in-java-1 › lessons › reading-text-files-line-by-line-in-java
Reading Text Files Line-by-Line in Java
To read a file line-by-line in Java, you can use the Files.readAllLines method to read the lines into a List<String>, and then iterate over the list using a for-each loop.
🌐
Java Guides
javaguides.net › 2019 › 07 › java-read-file-with-filesreadalllines-api.html
Java Files readAllLines() Method Example
June 21, 2024 - The Files.readAllLines() method in Java provides a simple and efficient way to read all lines from a file into a List<String>. By understanding how to use this method and handle potential exceptions, you can effectively manage file reading ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.nio.filenio.files.readalllines
Files.ReadAllLines Method (Java.Nio.FileNio) | Microsoft Learn
Read all lines from a file. [Android.Runtime.Register("readAllLines", "(Ljava/nio/file/Path;Ljava/nio/charset/Charset;)Ljava/util/List;", "", ApiSince=26)] public static System.Collections.Generic.IList<string>? ReadAllLines(Java.Nio.FileNio.IPath?
🌐
Davidvlijmincx
davidvlijmincx.com › home › quick solutions › reading a file in java
Reading a file in Java
February 21, 2023 - In the following example, we read all the lines of the file using Files.readAllLines(path) into a list of strings. Each entry inside the list represents one line of the file. In the for-loop, the content of the list is printed to the console. Using Java 8, we can also leverage streams while reading a file.
🌐
Blogger
javarevisited.blogspot.com › 2015 › 02 › how-to-read-file-in-one-line-java-8.html
How to read a File in One Line in Java? Files.readAllLines ...
This method reads all lines from a file. Bytes from the file are decoded into characters using the UTF-8 charset. It's equivalent to Java 7's Files.readAllLines(path, StandardCharsets.UTF_8).
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-read-file-line-by-line
Java Read File: Complete Guide with Examples | DigitalOcean
February 20, 2025 - package com.journaldev.readfileslinebyline; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; public class ReadFileLineByLineUsingFiles { public static void main(String[] args) { try { List<String> allLines = Files.readAllLines(Paths.get("sample.txt")); for (String line : allLines) { System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } } }
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-8177952
Loading...
FULL PRODUCT VERSION : java version ... Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode) ADDITIONAL OS VERSION INFORMATION : Microsoft Windows [Version 10.0.14393] A DESCRIPTION OF THE PROBLEM : If a text file ends with one or more empty lines, Files.readAllLines(Path, Charset) ...
🌐
YouTube
youtube.com › watch
How to Read All Lines from file in Java - YouTube
How to Read All Lines from file in Java
Published   March 10, 2024
🌐
GitHub
github.com › quidryan › OnJava-Examples › blob › master › files › ListOfLines.java
OnJava-Examples/files/ListOfLines.java at master · quidryan/OnJava-Examples
import java.nio.file.*; · public class ListOfLines { public static void · main(String[] args) throws Exception { List<String> lines = Files.readAllLines( Paths.get("../streams/Cheese.dat")); for(String line : lines) { if(line.startsWith("//")) continue; System.out.println( line.substring(0, line.length()/2)); } ·
Author   quidryan
🌐
Codebonneamie
codebonneamie.com › home › file read and write in java
File read and write in Java
April 10, 2021 - Files.readAllLines method reads a file and returns a list of string. It reads all data into memory, hence it is not recommended for large files. import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.charset.StandardCharsets; import java.util.st...
🌐
Shapehost
shape.host › home › resources › how to efficiently read a file line-by-line in java
How to Efficiently Read a File Line-By-Line in Java - Shapehost
November 29, 2023 - The java.nio.file.Files class provides a convenient method called readAllLines() that enables us to read all the lines of a file into a list of strings. This approach simplifies the process of reading a file line-by-line in Java.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.io.file.readalllines
File.ReadAllLines Method (System.IO) | Microsoft Learn
November 23, 2021 - Opens a file, reads all lines of the file with the specified encoding, and then closes the file. public: static cli::array <System::String ^> ^ ReadAllLines(System::String ^ path, System::Text::Encoding ^ encoding);
🌐
Coderanch
coderanch.com › t › 786023 › java › error
What does this error mean [Solved] (Java in General forum at Coderanch)
November 27, 2024 - Tim Cooke wrote:Looking at the docs for Files.readAllLines I wonder if the file you're reading isn't UTF-8?
🌐
Coderanch
coderanch.com › t › 744927 › java › java-jar-won-run
java jar won't run (Java in General forum at Coderanch)
August 18, 2021 - JavaRanch-FAQ HowToAskQuestionsOnJavaRanch UseCodeTags DontWriteLongLines ItDoesntWorkIsUseLess FormatCode JavaIndenter SSCCE API-17 JLS JavaLanguageSpecification MainIsAPain KeyboardUtility ... Uninstalling and reinstalling sometimes works. Does that happen for jar files that are opened with a double click?
🌐
GitHub
github.com › pathikrit › better-files › issues › 255
Ability to skip invalid characters · Issue #255 · pathikrit/better-files
August 23, 2018 - def linesSkipMalformed(file: File)(implicit charset: Charset = better.files.DefaultCharset): Traversable[String] = { @throws[IOException] def skippingBufferedReader(path: Path, cs: Charset): BufferedReader = { val decoder = cs.newDecoder.onMalformedInput(CodingErrorAction.IGNORE) val reader = new InputStreamReader(Files.newInputStream(path), decoder) new BufferedReader(reader) } @throws[IOException] def readAllLines(path: Path, cs: Charset): util.List[String] = { val reader: BufferedReader = skippingBufferedReader(path,cs) val result: util.List[String] = new util.ArrayList[String] var line: String = "" do { line = reader.readLine if(line != null) result.add(line) } while(line != null) if(reader != null) reader.close() result } readAllLines(file.path,charset).asScala }
Author   pathikrit
🌐
Physics Forums
physicsforums.com › homework help › engineering and comp sci homework help
Java: Reading a file into an array • Physics Forums
March 21, 2015 - Here's a way to do this using the java.nio.file.Files.readAllLines() method which returns a list of Strings as lines of the file.