Z
Z
zevilcube2019-08-24 13:38:44
Java
zevilcube, 2019-08-24 13:38:44

How to remove line break from text?

There is a file with text like


"
A1,
B2,
B3,
...
"

I read the file like this:
String text = "";
try {
 FileReader fr = new FileReader("file.txt");
 int c;
 while((c = fr.read())> 0){
  text = text.concat(String.valueOf((char)c));
 }

} catch (Exception ex) {
 ex.printStackTrace();
}

The text variable turns out to be multiline and I can't process it normally. I need to split it into smaller lines and put them in an array, I tried like this:
String[] BukviArray = text.replace("\n","").split(", ");

Can you please tell me how to remove all line breaks from text ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
illuzor, 2019-08-24
@iLLuzor

replaceAll()

D
Denis Zagaevsky, 2019-08-24
@zagayevskiy

You're reading wrong. Read immediately line by line using https://docs.oracle.com/javase/8/docs/api/java/io/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question