You can use the file class provided by Java 7. This is easier than expected.
It can be executed in one line:
byte[] bytes = new String("message output to be written in file").getBytes(); Files.write(Paths.get("outputpath.txt"), bytes);
If you have a File class, you can simply replace:
Paths.get("outputpath.txt")
in
yourOutputFile.toPath()
To write only one byte as you want, you can do the following:
Files.write(Paths.get("outputpath.txt"), new byte[1]); in file properties: size: 1 bytes
source share