Results 1 to 2 of 2
  1. #1
    eponcedeleon is offline Member
    Join Date
    Feb 2010
    Posts
    16
    Rep Power
    0

    Default writing to an opened file..

    I need to open a file, get before the end of the file "\n" and write to the file... i am trying to do this this way...however i cant find how to write to the file.

    Java Code:
    FileInputStream fstream = new FileInputStream("textfile.txt");
     // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) == null)   {
     // write to file
        write(snapshotFiles[i]);
    }
    //Close the input stream
     in.close();

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    366
    Rep Power
    6

    Default

    Java Code:
    java.io.FileWriter.FileWriter(String fileName, boolean append) throws IOException
    FileWriter

    public FileWriter(String fileName, boolean append) throws IOException

    Constructs a FileWriter object given a file name with a boolean indicating whether or not to append the data written.

    Parameters:
    fileName - String The system-dependent filename.
    append - boolean if true, then data will be written to the end of the file rather than the beginning.
    Throws:
    IOException - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
    --------------------------------------------------------------------------------

Similar Threads

  1. Replies: 9
    Last Post: 10-20-2009, 11:52 AM
  2. Replies: 3
    Last Post: 05-10-2009, 12:31 AM
  3. Replies: 9
    Last Post: 07-10-2008, 05:52 PM
  4. Deleting a File that is opened
    By ravian in forum Advanced Java
    Replies: 6
    Last Post: 01-30-2008, 03:05 PM
  5. Reading an already opened file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-25-2008, 07:50 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
  •