Answer the question
In order to leave comments, you need to log in
How to display a list on the screen?
Unable to extract text from file. I read text from a file and convert it to a stream of bytes, after that I want to write it to a list and display it on the screen. But at the output I get a set of numbers.
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) {
FileInputStream fis= null;
InputStreamReader str = null;
int b= 0;
try {
fis = new FileInputStream("D:/1.txt");
str = new InputStreamReader(fis, "UTF-8");
while ((b = str.read())!=-1) {
b = (char)b;
List<?> list = Arrays.asList(b);
list.forEach(System.out::println);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
str.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Answer the question
In order to leave comments, you need to log in
FileReader fileReader = new FileReader(filename);
int c;
while((c=fileReader.read())!=-1){
text+=((char)c);
}
fileReader.close();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question