Hot answers tagged


Apart from the performce issue, you should not call available at all, as it makes your code unnecessarily complicated. Instead, read into an int variable until the value gets -1, just like everyone else is doing this. You then need to add a (char) type cast to the append call. It's not necessary to create a new StringBuilder each time, you can just call ...


Replace try (FileInputStream fis = new FileInputStream(file)) { with try (InputStream fis = new BufferedInputStream(new FileInputStream(file))) { See also Why is using BufferedInputStream to read a file byte by byte faster than using FileInputStream?


Putting all of your code into a single file is bad. As a very VERY loose rule of thumb I try to avoid having any source file be more than a thousand lines of code, but the real rule to follow is that code should be broken up into modules that have coherent and comprehensible purposes, and those modules should live in their own files. The origin of rules ...

Only top voted, non community-wiki answers of a minimum length are eligible