title: How to Press Enter into File in Java
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/207947/java-how-do-i-get-a-platform-independent-new-line-character">Java: How do I get a platform independent new line character?</a>  </p>
  </blockquote>
  
  
  
  <p>I want to write <strong>enter</strong> into file with class <code>RandomFileAccess</code>, but I can't do it properly.</p>
  
  <p>What should I do ?</p>
  
  <p>Like this code : </p>
  
  <pre><code>char enter = '\n' ;
  outputfile.writeChar(enter);
  </code></pre>
  
  <hr>
  
  <p>I'm Using Windows....
  Thanks for your help but it didn't work :(</p>
  
  <pre><code>public class MainClass {
      public static void main(String[] args) {
          String BeforEnter = "It's Before Enter...";
          String Enter = System.getProperty("line.separator");
          String AfterEnter = "It must be on next Line...";
  
          File MyFile = new File("test.txt");
          try {
              RandomAccessFile TextFile = new RandomAccessFile(MyFile, "rw");
              TextFile.writeChars(BeforEnter);
              TextFile.writeChars(Enter);
              TextFile.writeChars(AfterEnter);
              TextFile.close();
  </code></pre>
  
  <p>I expected this Style of File :</p>
  
  <p>It's Before Enter...</p>
  
  <p>It must be on next Line...</p>
  
  <p>But it gets like this : :(</p>
  
  <p>I t ' s   B e f o r e   E n t e r . . .  I t   m u s t   b e   o n   n e x t   L i n e . . .</p>