Writing to File in Java: output displays differently in NotePad vs. Word/WordPad/NotePad++
<p>Below is the Java code for reading an existing text file called Sales.txt
and outputting a bar chart to a text file called storeReport.txt<br />
Each asterisk represents $100 in sales. </p>

<p>import java.io.*;</p>

<p>import java.util.*;</p>

<p>public class BarChart</p>

<p>{
    public static void main(String[] args) throws FileNotFoundException, IOException</p>

<pre><code>   {
       int[] s = new int[5];
       int[] b = new int[5];

       FileWriter fstream = new FileWriter("storeReport.txt");
       BufferedWriter out = new BufferedWriter(fstream);
       Scanner scanner = new Scanner(new File("Sales.txt"));

   int i = 0;

       while(scanner.hasNext())
       s[i++] = scanner.nextInt();
         System.out.println("SALES BAR CHART\n");
         out.write("SALES BAR CHART\n");

   for (i=0; i&lt;s.length; i++)
       {
        b[i] = s[i]/100;
        out.write("store "+ (i+1) +" : ");
        System.out.print("store "+ (i+1) +" : ");

        for(int j = 1; j &lt;= b[i]; j++) {
          System.out.print("*");
          out.write("*"); }
          out.write("\n");
          System.out.println();
       }

        out.close();  //Close the output stream
</code></pre>

<p>}<br>
}</p>

<p>When I open storeReport.txt in Word, or WordPad, or NotePad++ the output is displayed as was intended:</p>

<p>store 1 : <strong><em>*</em>**<em></strong><br />
store 2 : <strong></em>**<em>*</em>**</strong><br />
store 3 : <strong><em>*</em>**<em>*</em>**<em>*</em>*</strong><br />
store 4 : <strong><em>*</em>*</strong><br />
store 5 : <strong><em>*</em>**<em>*</em>**<em>*</em>**</strong></p>

<p>When I open the file in NotePad, the outputs are displayed all on one line. (I'm using Windows 7 and the latest jGrasp to compile and run the program.)SALES BAR CHART</p>

<p>The input file Sales.txt reads as such:</p>

<p>1000<br />
1200<br />
1800<br />
800<br />
1900</p>

<p>Anybody have an idea on why NotePad shows the output as:</p>

<p>SALES BAR CHARTstore 1 : <strong><em>*</em>**</strong><em>store 2 : <strong></em>**<em>*</em>*</strong><em>store 3 : <strong></em>**<em>*</em>**<em>*</em>**</strong><em>store 4 : <strong></em>**</strong><em>store 5 : <strong></em>**<em>*</em>**<em>*</em>****</strong></p>
