What is the easiest way to delete a line in a file?

Hi!
I have a file that is line oriented. I am using BufferedReader and BufferedWriter. My problem is, is how do I easily delet a line from a file? Sort of like this:
This
is
not
a
file
To:
This
is
a
file
My file then has to be resaved like that.

That was my idea what you did. Just making sure their
was no other way. There are surely other ways to do it.
As the file is dynamic, I have no
Idea how many lines long it is. Thank you.But you have not just an idea but the exact size of file!
That's just an example:import java.io.*;
class X {
     private static final String BAD_LINE = "so bad!";
     private static final String NEW_LINE = System.getProperty("line.separator");
     public static void main(String[] args) throws IOException {
          File f = new File("filename");
          //supposing in "worst" scenario nothing will be removed
          StringBuffer sb = new StringBuffer((int)f.length());
          String line = "";
          BufferedReader in = new BufferedReader(new FileReader(f));
          while((line = in.readLine()) != null) {
               //just filter out good lines
               if(!line.equals(BAD_LINE)) sb.append(line + NEW_LINE);
          in.close();
          //write back the processed file:
          BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("filename"));
          byte[] bout = sb.toString().getBytes();
          out.write(bout, 0, bout.length);
          out.close();

Similar Messages

  • What is the easiest way to delete a song or album?  Also, how do I get rid of the tunes it cannot convert or find?

    What is the easiest way to delete a song or album directly off the iPod?  Also, how do I get rid of the tunes it cannot convert so it does'nt run through them every time I upload an album or song?

    Right click the song you want to get rid of and there should be a delete button.

  • What is the easiest way to delete emails on an IPhone 4S?

    what is the easiest way to delete emails on an IPhone 4S?

    In the email list, swipe to the left and tap delete.  (iOS 7, but similar in iOS 6).

  • What is the easiest way to delete multiple duplicate songs?

    What is the easiest way to delete multiple duplicate songs?

    1. Google it. You may find third party applications that do what you want.
    2. Here is the link to an Apple discussion thread.
    https://discussions.apple.com/thread/3721976?start=0&tstart=0
    3. Backup before you do anything.

  • What is the easiest way to delete duplicates of photos

    I have ended up with many duplicates and  triplicates after uploading new photos trying to figure out the easiest way to manage these and delete the extras I have over 20,000 pictures.

    best way is to avoid them in the first place - have you by any chance imported an older iPhoto library into your current iPhoto library? Recently? Is the old library still available?
    THe best way to remove dupicates is using th epaid version of iPhoto Library Manager or Duplicate annilator
    LN

  • What's the easiest way to remove a line of a textfile?

    The line to remove can be any line in the file - not only the first or last one. How can I insert or append a line to a textfile?
    Is there any good tutorial for file operations?
    Thanks a million,
    Serano.

    If you wish to remove any line inside of a text file, you're going to have to use random access. The documentation for the class is located here:
    http://java.sun.com/j2se/1.3/docs/api/java/io/RandomAccessFile.html
    If you wish to append to a text file, you can use FileWriter. If you pass a boolean of value true as the second argument to the constructor, it will append to the file.

  • What's the easiest way to manage my music on my iPhone 4S, espeially to delete duplicates

    It is difficult for to manage playlists, smart playlists and restored playlists. What is the easiest way to go through my 7.9 Gigs of music on the iphone and remove duplicates. Is there a way to do this on the phone itself or do I have to go through syncing?

    Hello ihweiner,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    How to find and remove duplicate items in your iTunes library
    http://support.apple.com/kb/ht2905
    Best of luck,
    Mario

  • I am using Iphoto 11 ver 9.4.3 on mac using oxs 10.8.5 i want to export calendar projects to an external hard drive. what is the easiest way to do this? i have tried export and import but it didn't seem to work.

    I am using Iphoto 11 ver 9.4.3 on mac using oxs 10.8.5 i want to export calendar projects to an external hard drive. my goal is to store them in an external hard drive so it doesn't use up memory on the mac hard drive. is it possible to copy the specific projects without copying the entire library? what is the easiest way to do this? i have tried export and import but it didn't seem to work.

    What do you not understand?
    You can duplicate the iPhoto library (command - D ) and delete everything except the project and its photos from the copy and move that
    Or
    However the calendar takes very little space - it is simpy database entries - it is the photos in the calendar that take space - and for most people you would wnat to keep those photos in your library
    you can use a photo in 50 calendars and it still is only one photo in your library - as I explained calenders do not exist as such - they are simply database entries telling iPhotop how to display the calendar - they take almost no space at all
    LN

  • What's the easiest way to make a password system? 10 Duke Points!

    Hello everyone,
    What's the easiest way to make a password system in java?
    I'd like to be able to:
    1) store passwords for about 6 people.
    2) have the people only interact with my program using my Eclipse console with no GUIs, pop-ups or Swing code.
    3) let the people have the ability to create/delete their own passwords and logins. (ideally)
    Having searched around the Internet, it seems that the options are to:
    A) have code that allows users create files, write to files, read from files.
    B) have code that serializes objects - this seems pretty difficult.
    C) have code that has a hash table of some kind - although I don't really know hash tables very well and am not sure if they can store data over time unless the program is always running (which is an option).
    D) use some sort of javadoc like PassWordCallback - this one looks the easiest as the code already seems to be there but I'm not really sure how to include this type of stuff in my code.
    E) have code that allows users to input their password, which I've given them on a piece of paper, and then allow the code to match it to a file - this wouldn't let the users create their own passwords though.
    Anyway, hope you can help!
    I have a 'Head First Java' book and a 'Java for Dummies' book if you know of anything directly useful in these books.
    Edited by: woodie_woodpeck on Jan 11, 2009 3:51 AM

    bastones_ wrote:
    Using GUIs and Swing is really easy, I have only been using Java for a week now and I have already made a simple application with events. First of all Swing is a package and you need to import it (as described in the documentation).
    When you click on the Swing package in the documentation to the second frame you'll see JFrame when you scroll down. JFrame's are the main windows on your screen. JFrame is a class therefore it needs to be instantiated (making an instance of that class so we can use it). After all, everything is based around classes.
    JFrame frame = new JFrame("Title here");
    Note: The "JFrame" before the frame vaiable name is the "data type" of the variable, really we're making an object type (I think its called) just like we'd do String frame if we wanted to make a frame variable that is of type String.
    As explained in the [JFrame section of the documentation|http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html] in the "Constructor Summary" section is the different types of Construtors that are made available to us when we instantiate the JFrame class. One of the construtors available are:
    JFrame(String title)
    ... which is exactly what I did above in the brackets/parentheses (its telling us we can add a String title).
    Remember constructors do not have any return type or anything and is not a method, because it is the same name as the class and when we instantiate we call the constructor. And so the JFrame class has many constructors, one is for making a title for our JFrame and another is just instantiating without a title. If there wasn't the JFrame(String title) and just JFrame() constructor, we wouldn't be able to add a title as we made an instance of JFrame.
    So once we've made an instance of JFrame we have all the methods available (and all of the methods are shown in the API documentation).
    Hope you understand now :).Wow. Thanks a lot bastones_. I think Swing is just a bit beyond me at the moment and will require quite a bit of time for me to master. Is there not an easier way of making a password system? I think that A (see above) seems the easiest for me at the moment and D (see above) would be nice if I could just figure out how to use the javadoc.

  • What is the easiest way to copy individual photos from a pc to ipad?

    what is the easiest way to copy individual photos from a pc to ipadair 2?  I have been told that transferring via itunes creates one mass file from which individual photos cannot be manipulated.

    Photos synced from iTunes cannot be deleted one at a time if that's what you mean. They can be manipulated, if manipulated means editing or moving them into folders that you create on the iPad in the photos app.
    I agree with Procyon256 that emailing is probably the easiest way for one at a time, but there are also WiFi transfer apps that are pretty nice for this purpose, I use this one.
    http://www.wirelesstransferapp.com/

  • What is the easiest way to take out white background in elements 12?

    what is the easiest way to take out white background in elements 12?

    Try this:
    Open the program and go to Expert tab
    Double click the background layer to convert it to a regular layer
    Get the magic wand tool out of the toolbox. On the tool's option bar, check "contiguous" or leave it unchecked depending on the presentation of the white background. Start with tolerance setting 32; you may have to adjust it down - - depends on picture
    Left click on a white area and hit delete on keyboard
    Press CTRL+D to get rid of the marching ants
    If you encounter a problem, post a representative picture here for targeted guidance. You can do that via the camera icon in the reply box, but not in an e-mail reply.

  • What's the easiest way to transfer files to new mac?

    My first mac was a Macbook (purchased in August 2010) and I'm upgrading to the new 13" Macbook Pro with retina display. What is the easiest way to:
    1) transfer files to the new laptop
    2) delete files off my old macbook to share with a family member--possibly thinking of return to factory settings.
    I have a 1TB external hard drive and I use the cloud on all of my devices (also have iPhone and iPad synched to the cloud).

    Welcome to Apple Support Communities
    1. The best way to transfer files from another computer is by using Migration Assistant > http://pondini.org/OSX/SetupLion.html Your new MacBook Pro will ask you to restore from another computer during its initial setup.
    2. If you haven't got a lot of apps you installed, you can just create a new user and delete the old one, so you won't have to reinstall Mac OS X.
    To do it, open System Preferences > Users and Groups (or Accounts), press the + button and create an admin user. Then, log in this user, go to System Preferences > Users & Groups, and remove the old account

  • What's the easiest way to update my site regularly?

    What's the easiest way to update my site? I update with new content every month, sometimes more often. (I don't use .mac) When I do, I delete my whole site, then have to upload the whole site with it's updates (the main file along with the index file).
    Is there a way to only update, let's say, ONE page? And if so, will I still have to delete that page?
    Thanks!
    http://faithmountainaz.com/FaithMountain/Home.html

    Hi,
    I wrote my personal experience in that thread:
    http://discussions.apple.com/thread.jspa?messageID=5431205&tstart=0#5431205
    I think you will find all you need
    If not, just ask...
    Enjoy your day,
    Cédric

  • What's the easiest way to retrieve lost music files?

    I was using a file sharing program and I saw that all of my music files were being shown in its share folder, and I did not want to share them. I assumed the files were duplicates and deleted them. When I realized the actual files were being deleted I stopped it, but not before several hundred files were lost. Here is the error message I get when I plug in my iPhone.
    http://i174.photobucket.com/albums/w91/Candyman_8877/Untitled1.png
    It says there is a hundred files missing, but when I count the "!" marks in iTunes, I got to 100 by the letter C, so there is definitely several hundred files missing. I have my machine backed up with time machine, and I also have a faily recent copy of my music folder on an external drive.
    I'm wondering, what is the easiest way (using the fewest clicks) to restore all of my missing music files? I'm trying to avoid searching out and restoring every missing file individually, as there are hundreds and this would be very time consuming.
    Thanks for any help and advice,
    mcfada

    If you are confident the Time Machine backup is current, recover your iTunes folder and all its contents from there.

  • What is the easiest way to create and manage very big forms?

    I need to create a form that will contain few hundred questions. Could you please give me some advise on what is the easiest way to do that? I mean for example is it easier to create everything in Word (since it is easier to manage) and than create a form based on that?
    My concern is that when I will have a very big form, containing different kinds of questions and with many scripts, managing it during work will be slow and difficult, for example adding a question in the middle of the form which would require moving half of the questions down which could smash the layout etc.
    What is the best practise for that?
    Thanks in advance

    Try using Table and Rows for this kind of forms. These forms will have the same look throught with a question and and answer section..
    In the future if you want to add a new section, you can simply add rows in between..
    Thanks
    Srini

Maybe you are looking for

  • Can I get a List of all the running processes in the system using java ?

    I want a complete list of all the Running processes currently in the system. List of running processes is like, in MS Window environment while we presses ctrl + alt + del and we get a small window containing a list of all the running processes curren

  • Moving TM Drive to New Mac

    I've been backing up from my MacBook Pro to a wired drive for a while. I've just got myself a Mac Mini and plugged the drive in there instead. I'm trying to carry on using the same Time Machine backup for the MBP wirelessly, with mixed success so far

  • SharePoint 2013 - Power View Version Error

    getting the attached error. please help me, SSAS stands at latest CU 7 SQL 2012. Checked the necessary permissions. but not luck.  we are at SP 2013 and SQL 2012 CU7. Thanks, Ram Ch

  • My profiles and bookmarks keep vanishing, I am running windows 7.

    New computer, 2 months, running windows 7. Installed latest firefox. It has crashed a few times, and all of my profiles and bookmarks have disappeared 3 times now. Unable to recreate event. Running Trend Micro AV. Any ideas?

  • Java Wireless Toolkit Error

    Hello everytime I try to run a program in the wirless toolkit, the program transfers to the emulator but when I click launch I get this error Running with storage root DefaultGrayPhone Method............: 100d2aa8 'com/sun/midp/midlet/MIDletState.cre