reads its contents from a .txt, with similar information in the text as follows:
Info 1
Info 2
Info 3
.
the code I wrote is
public class FileMessage {
public static void main(String[] args) throws Exception {
File file = new File("D:"+File.separator+"test.txt");
if(!file.exists()){
throw new Exception("");
}
InputStream is = new FileInputStream(file);
byte[] byt = new byte[(int)file.length()];
is.read(byt);
is.close();
String result = new String(byt);
result.replace("\r", "");
result.replace("\n", "");
System.out.println(":"+result);
}
}
the data read is always divided into multiple lines, but the requirements need to be displayed on one line. I would like to ask you why the replace () method does not work and remove the newline characters in the string. Or is there any other more elegant way to implement it?