If you want to read a file in Java that has UTF-8 characters, make sure when you create a FileReader object you choose the constructor FileReader(File fine, Charset charset), let's see an example,
File textFile = new File("\\usr\\data\\text.csv");
try {
FileReader fileReader = new FileReader(textFile, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
}
You can choose the UTF_8 static final string from java.nio.charset.StandardCharsets class.
⚡️ Check the StandardCharsets class for other encodings: US ASCII, ISO-LATIN-1, ISO-8859_1, UTF-16BE, UTF-16, UTF-16LE
More Posts related to Java,
- Convert Java Map Collection Object to JSON String using Jackson
- Java Stream flatmap() Examples
- [Fix] Instant java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Years
- How to run Java Unit Test cases with Apache Maven?
- How to check if Java main thread is alive
- [Fix] java: incompatible types: incompatible parameter types in lambda expression error
- Parsing CSV file using Java code example (Comma Separated File)
- Unhandled exception type InterruptedException : Java Threads
- Native getClass() method from java.lang.Object Class Explained with examples.
- Java Jackson ObjectMapper Class with Examples
- Java 8 Streams map() with examples
- Java 8 - Convert List to Map Examples
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- Java Stream with Multiple Filters Example
- How to Clear StringJoiner in Java 8
- Spring 5 IoC Example with application Context XML (ClassPathXmlApplicationContext) and Gradle.
- How to get end of line (EOL) or new line character \r \n in Java
- Spring Boot CRUD Examples using JDBCTemplate
- Delete a File in Java with Examples
- Implementing Insertion Sort Algorithm in Java Program
- Java JDBC Batch Update Example with PreparedStatement
- Java JDBC Select Multiple Records from table as List using PreparedStatement
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated
- How to fix Java HTTP java.net.UnknownHostException
- Java 8 Display time in 12 hour AM PM format
More Posts:
- How to install SpaCy (NLP Library) on Mac - Python
- fix fatal: --local can only be used inside a git repository error - Git
- Check Bluetooth is turned on or off on Android device programmatically [Java Code] - Android
- Center align text in TextView Android Programming - Android
- [Android] RuntimeException: Unable to start activity Need BLUETOOTH permission - Android
- Fix - Error:Invalid Gradle JDK configuration found (Android Studio) - Gradle
- SDK Manager: failed to install : Android Studio on Windows - Android-Studio
- The Date Command and its usage [Linux - Unix - macOS] - Linux