I have a java program where I am writing to a file using OutputStream. Everything is working fine. Upon completion of the program, I see data in my file. However, I would like to see this data on the System.out as well.
How can I convert OutputStream to a String so that I can simply System.out.println(); it? I tried fos.toString() but that prints java.io.FileOutputStream@1ed2e55e
OutputStreamto write to the file toSystem.out.println()FileInputStreamto read from the file what you have written to it - then use aBufferedReaderto read it line by line and print it. This only makes sense if you want to see that your data was written correctly.new String(Files.readAllBytes(Paths.get("file.txt")), "UTF-8").fos.write((byte) mybyte)however, when I do the same toString s = (byte) mybytei get errorsSystem.out.print((char) mybyte);orsb.append((char) mybyte);.