1 Reply Latest reply: Mar 28, 2008 11:59 AM by 796440 RSS

    hi i want to know how to write a tab to a file

    807591
      hi,
      this is ayesha.
      I have a requirement wherein i am writing to the windows\hosts file an ipaddress followed by tab followed by domain name.
      ex:

      127.0.0.1 localhost
      192.133.4.34 ayesha.com
      113.24.5.34 basic.com

      And the code i have used is:

      public static void main(String[] args) {
                // TODO Auto-generated method stub
      System.out.println("*****************starting of the program");
      //System.out.println("irfan"+'\u0009'+"lets see");
      //System.out.println("irfan");
      try {
      File f = new File("C:\\WINDOWS\\system32\\drivers\\etc\\hosts");
      RandomAccessFile raf = new RandomAccessFile(f,"rw");

      // Read a character
      char ch = raf.readChar();

      // Seek to end of file
      raf.seek(f.length());

      // Append to the end
      // raf.writeChar('\n');
      String toBeSubstituted=System.getProperty("line.separator");

      raf.writeBytes(toBeSubstituted+"aString"+"\t"+"end"+"\t"+"end");
      // raf.writeBytes("\t"+"end");
      raf.writeBytes(toBeSubstituted);
      raf.writeBytes(toBeSubstituted);


      System.out.println("ending the application*******************************************************");
      raf.close();
      }



      But my problem is when i write:

      raf.writeBytes(toBeSubstituted+"aString"+"\t"+"end"+"\t"+"end");

      I get the output on a new line as :
      astring end end(ie astring followed by space followed by tab followed by end)

      But i want to write "astring" followed by tab followed by end..................

      Can anyone help me in this????????????????????
      And why it is printing the space instead of tab the first time and a tab the second time.
      Regards,
      Ayesha.