Answer the question
In order to leave comments, you need to log in
How to convert a char (in the form of a character) to a string in Java?
I am using FileReader to read from a file. Using this class, you can read information character by character. The read() method reads a character from the file, but returns it as an int. And how to get the character itself from this character code and write it to string?
Answer the question
In order to leave comments, you need to log in
public class App {
public static void main(String[] args) throws FileNotFoundException {
try (FileReader in = new FileReader("c://file.txt")) {
String value = new String(new char[] { (char) in.read() }); // Первый символ из текстового файла
} catch (IOException err) {
err.printStackTrace();
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question