Delete some lines from file...

Hi,
I'm using this code
      File file = new File(sFile);
      if (!file.exists())
        file.createNewFile();
      fout = new PrintWriter(new OutputStreamWriter(new FileOutputStream(sFile , true)) , true);
PrintWriter fout;
...When file has more then (let's write) 1000 lines, I want to delete last 100 from file.
Can someone help me to do that? Can you posto me a part of code which will done that?
Thanks.

If you want to use "standard" (serial) IO, which reads from the beginning of the file, create a line counter, read the file line-by-line, and when the file size limil is reached, close the file - remaining lines will be truncated from the file.
If the file lines are all equal in length, then you can use the RandomAccessFile methods to directly seek to the desired line and delete lines after that point using the class methods - see the seek and setLength methods.

Similar Messages

  • How do I delete some pages from an existing pdf file?

    I have an existing pdf file that is too large to send to some people. How can I delete some pages from this existing pdf file, and break it up into two files?

    Acrobat
    You can download a 30 day trial at that link.
    You may also be able to do it with CreatePDF, but I'm not sure.

  • How to read some lines from a text file using java.

    hi,
    i m new to java and i want to read some lines from a text file based on some string occurrence in the file. This file to be read in steps.
    we only want to read the file upto the first Occurrence of "TEXT" string.
    How to do it ,,,
    Kinldy give the code
    Regards,
    Sagar
    this is the text file
    dfgjdjj
    sfjhjkd
    ghjkdg
    hjkdgh TEXT
    ikeyt
    ujt
    jk
    tyk TEXT
    rukl
    r

    Hendawy wrote:
    Since the word "TEXT" is formed of 4 letters, you would read the text file 4 bytes by four bytes. Wrong on two counts. First, the file may not be encoded 1 byte per character. It could be utf-16 in which case it would be two byte per character. Second, even if it were 1 byte per character, the string "Text" may not start on a 4 byte boundary.
    Consider a FileInputStream object "fis" that points to your text file. use fis.read(byte[] array, int offset, int len) to read every four bytes. Convert the "TEXT" String into a byte array "TEXT".getBytes(), and yous the Arrays class to compare the equality of the read bytes with your "TEXT".getBytes()Wrong since it relies on my second point and will fail when fis.read(byte[] array, int offset, int len) does not read 4 bytes (as is no guaranteed to). Check the Javadoc. Also, the file may not be encoded with the default character encoding.
    The problem is easily solved by reading a line at a time using a BufferedReader wrapping an InputStreamReader wrapping a FileInputStream and specifying the correct character encoding.
    Edited by: sabre150 on Apr 29, 2009 2:13 PM

  • I have purchased adobe pdf pack so i can delete some text from my converted files, this will only let me add text but not delete any, please help

    i have purchased adobe pdf pack so i can delete some text from my converted files, this will only let me add text but not delete any, please help

    I tyhink that you need ExportPDF, Adobe ExportPDF (read only). In any case, thius may help: Cancel your membership or subscription | Acrobat.com online services

  • N82: Memory full. Delete some data from phone memo...

    memory full. delete some data from phone memory
    i deleted all of the messages in inbox and in memory card. i also tried *#7370#. stil the memory is full. i check the phone memory status everytime i delete the messages and it will show available memory for about 30kb. when i restart the phone and check the phone memory, it will indicate that it has 0 kb left. i didn't installed any application in it.
    Message Edited by katnix on 13-Jul-2008 01:39 PM

    proper advice???? that's the advice i gave, take it or leave it. it's not for you tell me what's proper or not.
    i don't remember seeing your name in the thread above, and i don't remember you TELLING me before that you don't want to format.
    now just not to go into alot of words. there is a better way you can use to talk to people. because we are trying to help. if you like what we suggest, fine, if not, wait for another suggestion or come with one yourself.
    if you have a registery cleaner or a temp file cleaner for symbian , please be so kind to offer it's name here.
    Fear not those who argue but those who dodge

  • I have deleted some apps from iPad.

    I have deleted some apps from iPad. When I connect it to Mac, Itunes starts to sync ipad and all apps installed back!!! Why??? I wanted to send one m4a file to iPad, but iTunes started a huge sync process all over 3 hours and + 1 hour I was deleting not needed apps. Please - help! We all need one app iTunes - to have a simple tool to sync devices, but this process became NOT simple. Now I am afraid of it! I want to do everything not to connect my iPad to Mac.
    Please - make it simplier! I want to have a control of this process and do what I want to do.

    Thank you very much)

  • [Solved] Shell script to read unhashed lines from file.

    Hello.
    I want to write a shell script  (it can be bash,sh,ksh,csh or zsh) that will be:
    1.Read unhashed lines from file named mirrors.conf.
    2.Put them in ~/.profile as PKG_PATH=line catted from mirrors.conf.
    Just like as mirrors.conf file for pacman.
    Now it can cat lines but how to put them in files as PKG_PATH?
    Thanks for answers.
    Last edited by SpeedVin (2010-03-01 17:33:20)

    res wrote:
    ^ IFS is not necessary here; it won't mess with the white space:
    $ echo 'args with formatted spaces ' | while read -r; do echo "$REPLY"; done
    args with formatted spaces
    It matters for leading/trailing whitespace:
    $ echo ' after some ' | while read -r line; do echo "<$line>"; done
    <after some>
    $ echo ' after some ' | while IFS= read -r line; do echo "<$line>"; done
    < after some >

  • How can I delete some music from my iCloud but not from my iTunes in my computer? please??

    how can I delete some music from my iCloud but not from my iTunes in my computer? please??

    iCloud doesn't store your music.

  • How can i delete some books from ibook?

    How can i delete some books from ibook? It says: this book can't be opened. The book is corrupt. I can't open and I can't delete it

    I was unable to delete a book sample from my iPhone 5s running iOS 7.  This seems to be what worked for me.  I went to the Library and clicked "edit" in upper right side of the screen.  I then tapped one time on the book I wanted to remove and a blue check appeared at the bottom right corner of that book (presumably you could tap several at a time)  Anyway, when the blue check is on the book, you will see in the upper left of the screen the word "Delete" (mine was in red) I clicked that and then a confirming dialog came up from the bottom of the screen with the choices of "delete" or "cancel".  I chose "delete" and the book was gone.  Hope this helps.

  • I have deleted some photos from camera roll which are taken by today but my icloud is bacuped on yesterday night.how can i get those photos.please anyone tell me because they are very important

    I have deleted some photos from camera roll which are taken by today but my icloud is bacuped on yesterday night.how can i get those photos.please anyone tell me because they are very important

    Are those photos on PhotoStream?

  • TS4036 I purchased an iphone for my daughter and we are using the same account and she deleted some contacts from her phone and they were deleted off of my contacts as well. Is there a way to use icloud backup to reinstall the contacts to my phone?

    I purchased an iphone for my daughter and we are using the same account and she deleted some contacts from her phone and they were deleted off of my contacts as well. Is there a way to use icloud backup to reinstall the contacts to my phone?

    Welcome to the Apple community.
    You can only restore them from a Computer backup. This has occurred because you are sharing an iCloud account. ideally you should each have your own iCloud account, that way you can each manage your own mail, contacts, calendars, documents etc and avoid unintentional deletions and unwanted editing. If there is information you wish to share between you, this can be done with a secondary account.
    Having separate iCloud accounts, doesn't mean you have to have separate iTunes accounts, so whilst you keep your personal data separate, you can continue to share music, apps, books, TV shows, movies etc.

  • HT1386 i deleted some songs from my iphone 4. now when i try to re-add them to my phones itunes, they wont add. whats wrong? new songs add. but not the old ones! help please

    i deleted some songs from my iphone 4. now when i try to re-add them to my phones itunes, they wont add. whats wrong? new songs add. but not the old ones! help please

    Hey renie1515,
    Thanks for using Apple Support Communities.
    When you download past purchases on an iOS device or computer, that device or computer becomes associated with your Apple ID. This article describes how to manage these associations.
    iTunes Store: Associating a device or computer to your Apple ID
    http://support.apple.com/kb/ht4627
    Once a device or computer is associated with your Apple ID, you cannot associate that device or computer with another Apple ID for 90 days.
    Note: Removing a device from your Apple ID does not override the 90-day timer. You must wait 90 days from the day the device was first associated with your Apple ID before it can be associated with another Apple ID.
    Have a nice day,
    Mario

  • HT4847 i deleted some photos from my camera roll on ipad by mistake trying to get more icloud storage.  can i get them back?

    I was trying to free up icloud storage in order to back up my iphone 5 using my ipad.  I mistakenly deleted some photos from my camera roll and they were deleted from both iphone and ipad photo albums.  Can I retrieve them somehow or are they gone forever?  Now I read that doesn't help to free up space...not sure what does free up space so I can back up my phone again.  Help!

    Welcome to the Apple Community bonwal.
    Are you sure you deleted them from your camera roll and not from photo stream.

  • Hi I have a Iphone4 in using. I couldn't find Safary, E-mail and notes from my phone one day. I made this mistake when I want to delete some programe from my phone. Who can help I recovery my phone please.

    Hi
    I have a Iphone4 in using. I couldn't find Safary, E-mail and notes from my phone one day. I made this mistake when I want to delete some programe from my phone. Who can help I recovery my phone please.
    Thanks

    Hello, HenryWang2103.
    Thank you for visiting Apple Support Communities.
    The Safari, Email and Notes applications are native to the iOS and is unable to be deleted.  Since this is the case, they are either in a folder on the iPhone, on another page or Restrictions are enabled.  You can also search for these Apps on the iPhone by touching the screen and sliding your finger down.  Here is some information regarding these features.  The information about folders is located in the user guide below.
    iPhone User Guide
    iOS: Understanding Restrictions (Parental Controls)
    http://support.apple.com/kb/HT4213
    Cheers,
    Jason H.

  • HT4847 On startup my macbookair says start up disk full/delete some files. When I look at storage disk utility I see 51GB of a possible 60GB is used with Other. What is Other? and how can I view and delete some of these files?

    On startup my macbookair says start up disk full/delete some files. When I look at storage disk utility I see 51GB of a possible 60GB is used with Other. What is Other? and how can I view and delete some of these files?

    A MacBook will use Time Machine to make local backups so that when connected to an external drive it will backup a lot faster.
    to disable this, you must use a command under terminal.
    to locate terminal, do a search for it under spotlight (the magnifying glass on the top right corner), should be the first hit.
    once under terminal, type the following text exactly:
    sudo tmutil disablelocal
    hit enter.
    you will be asked to input your password, if you do not have a password, you will have to create one before performing this command. after entering your password, hit enter again and close terminal.
    in a few minutes the space taken up by time machine should be cleared.

Maybe you are looking for

  • All driver for Hp Pavilion 15-n213sx windows 7&8.1

    please All driver for Hp Pavilion 15-n213sx windows 7&8.1 This question was solved. View Solution.

  • Export to word/text file

    How to i export a html db report into .doc or .txt file. Once exported this file should be editable. Thanks a lot sudha.

  • File name reverts back to original file name from camera

    In iPhoto I changed all the names of my pictures from what the camera assigned them. I can see the title on each picture. Then when I go to attach the picture  to an email it reverts back to original name from the camera. It does the same thing when

  • Itunes creating many playlists when dragging mp3's to itunes library

    I have an external hard drive, and hooked it up to a new computer.  Whe I dragged the mp3 collection to itunes, it created hundreds of playlists, some being albums and some being artists lists. Is there a setting I can change to keep itunes from rand

  • Oracle Report REP-1219

    I am getting error 'REP-1219 body has no size or width' when I run a report from Oracle Applications...But it's fine when I execute the report from within Report Builder.