reading text file with utf-8 encoding using java

Use import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; public class test { public static void main(String[] args){ try { File fileDir = new File(“PATH_TO_FILE”); BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(fileDir), “UTF-8”)); String str; while ((str = in.readLine()) != null) { System.out.println(str); } in.close(); } catch (UnsupportedEncodingException e) { … Read more

is there an existing FileInputStream delete on close?

I know this is a fairly old question; however, it’s one of the first results in Google, and Java 7+ has this functionality built in: Path path = Paths.get(filePath); InputStream fileStream = Files.newInputStream(path, StandardOpenOption.DELETE_ON_CLOSE); There are a couple caveats with this approach though, they’re written up here, but the gist is that the implementation makes … Read more

Testing IO performance in Linux [closed]

IO and filesystem benchmark is a complex topic. No single benchmarking tool is good in all situations. Here is a small overview about different benchmarking tools: Block Storage: IOMeter – Highly customizable and allows to coordinate multiple clients. Needs a Windows PC for the coordination application. Developed by Intel. On Linux, take maximum rates of … Read more

node js: does fs.rename overwrite file if already exists

Short answer: yes Long answer: I created a script to check it: var fs = require(‘fs’); Create two files: fs.writeFileSync(‘a.txt’,”This is a file”) fs.writeFileSync(‘b.txt’,”This is another file”) Rename: fs.renameSync(‘a.txt’,’b.txt’); Check if it was overriden: var text = fs.readFileSync(‘b.txt’, “utf-8”); console.log(text) // This is a file