Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Problem With File Writing

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Location
    Bengaluru
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Problem With File Writing

    Hi,
    I am writing some data (like some 10000 bytes) to a file Once it reaches the maximum size then the first data has to be deleted and the new data should be written at the bottom.

    Ex:
    12345 --Need to delete this line(First Line)
    12345
    .
    .
    .
    .
    12345 --Need to insert this line(At the bottom)

    Could somebody suggest me something


  2. #2
    Member mjr's Avatar
    Join Date
    Jan 2012
    Location
    127.0.0.1
    Posts
    36
    My Mood
    Fine
    Thanks
    8
    Thanked 2 Times in 1 Post

    Default Re: Problem With File Writing

    I guess one approach is that if each piece of data is on one line, you could use an array. Read the data from the file into an array, using the line breaks to separate the elements of the array, so you get something like this:

    theData[0] = '12345';
    theData[1] = '23456';
    etc...

    Then just assign the next value to a new element in the array (I think this is possible...), then delete the first element of the array.

    Then iterate over the array, and write back to the file.

    That's just off the top of my head. There are probably better solutions.

Similar Threads

  1. Stuck on Writing to File
    By java_kiddy in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 15th, 2012, 05:47 PM
  2. counting the values in input file and and writing the output to a file
    By srujirao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 8th, 2012, 02:48 PM
  3. Writing to aserializable file
    By ranjithfs1 in forum File I/O & Other I/O Streams
    Replies: 7
    Last Post: March 18th, 2012, 10:38 AM
  4. Writing in a file using Java
    By JavaPF in forum File Input/Output Tutorials
    Replies: 4
    Last Post: December 17th, 2011, 04:33 PM
  5. Writing Output To New File
    By Scottj996 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 6th, 2010, 07:25 PM