I'm trying to export my console output to the text file. This output also comes from the serial port. But, I couldn't do it, it prints only one line. Can anyone help me? The code that I wrote is below.
String input = new String(buffer, 0, len); // convert buffer to string
myLinkedList = removeComma(input); //format string data
String[] array = myLinkedList.toArray(new String[myLinkedList.size()]); // put array the formatted data
PrintStream fileOut = new PrintStream(new FileOutputStream("C:\\Users\\khas\\Desktop\\output.txt"));
System.setOut(fileOut);
for (int i = 0; i < array.length; i++) {
System.out.print(array[i] + " ");
}
System.out.println("");