Results 1 to 2 of 2
  1. #1
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default writing to a file

    I am randomly accessing a file and want to append text at the end of the file. I am trying following code.

    Java Code:
             File file = new File("C:\\myFile.txt");
             RandomAccessFile raf = new RandomAccessFile(file, "rw");
             
             raf.seek(file.length());
             raf.write("MyMessage");
    I get exception at following like:

    Java Code:
    raf.write("MyMessage");
    saying:
    Java Code:
    The method write(int) in the type RandomAccessFile is not applicable for the arguments (String)
    Any clues??

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    10

    Default

    Look in the Methods Summary section of the RandomAccessFile class api.
    There are three write methods none of which take a String argument. Methods that take a String argument are writeBytes(String s) and writeUTF(String str).

Similar Threads

  1. writing to a excel file from java program
    By priyankabhar in forum New To Java
    Replies: 15
    Last Post: 01-17-2014, 01:39 PM
  2. writing and reading unicode characters from a file
    By ranoosh in forum Advanced Java
    Replies: 4
    Last Post: 09-28-2008, 04:34 AM
  3. Writing to a file (at the end)
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 10:22 AM
  4. Writing UTF to file using writeUTF
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-22-2008, 09:19 PM
  5. Help with File reading and writing
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 06:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •