I have a line that I format with a method System.out.format(), I do something like:
System.out.format("I = %3d var = %9.6f", i, myVar);
but when I try to write this formatted string to a file, I only get something like "java.io.PrintStream@84fc8d".
After studying the documentation, it was clear that this method is a bit like System.out.print()and just returns PrintStream for display (for example, in the console), so I tried to convert it with .toStringor String.valueOf(), but I get the same result.
So, I was wondering if there is a way to format the string, as the method does String.out.format(), but in a way that will be writable in a file?
Here is roughly the code I'm using (just creating useful parts)
WRITE_MY_LINE(System.out.format(" I = %3d var = %9.6f", i, myVar).toString());
WRITE_MY_LINE(String.valueOf(System.out.format(" I = %3d var = %9.6f", i, myVar)));
public static void WRITE_MY_LINE(String line) {
buff_out = new BufferedWriter(new FileWriter(ascii_path, true));
buff_out.append(line);
buff_out.newLine();
buff_out.flush();
}