Java output file doesnt recognise \n as linebreak

Posted by oderebek on Stack Overflow See other posts from Stack Overflow or by oderebek
Published on 2012-04-08T22:56:38Z Indexed on 2012/04/08 23:30 UTC
Read the original article Hit count: 253

Filed under:
|

for a Java project for a University Class I have a method that saves ASCII images as a uniline string and another method called toString rebuilds this ASCII image and returns as a string. When I run my program on the Eclipse my output looks on console alright and multiline, and there are line breaks where they should be. But when I run it with the command line with a redirected outputfile

java myprogram < input > output

the text in the output is uniline without line breaks

Here is the code of the method

public String toString(){

    String output = "";

    for(int i=0; i<height; i++){
        output=output+image.substring(i*width, i*width+width)+"\n";

        }
    return output;  
}

What should I do so I can get a multiline output text file

© Stack Overflow or respective owner

Related posts about java

Related posts about output