I have a small file test.txt contains a Long number inside while another piece of java code to read the Long constantly from the file.
Here is the steps:
Run
echo "123" > test.txt
then if you go to the test.txt file, vim test.txt -> :set list, you will see the file looks like:
123$
I have a piece of java code does the following:
byte[] testBytes = File.readAllBytes(test.txt);
String testString = new String(testBytes); // in debug mode, testString looks like "123\n"
long bytesEverRead = Long.parseLong(testString); // this line throws exception because parseLong("123\n") won't work
As you can see above, “123\n” is being read from the file which cause my parseLong failed. How can I read 123 out from test.txt without having \n with it. What’s the best way to handle this?
You could use