Open/edit file

I need to open a file, and edit part of the file based on some static text in that file. For example, lets say the text file looks something like this:
a
b
c
1
2
1
a
b
c
I need a program that will open the file, and delete everything from the first 1 to the last 1, and do nothing if no 1's exist.
Afterwards, save the existing file.
Can someone please show me how to do this?
Thanks.

I finished writing the program I was asking about. In case anyone needs anything like this in the future, I have posted the program here(w/ a few modifications):
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.File;
import java.util.Collection;
import java.util.ArrayList;
public class ABC{
   // Main method
   public static void main(String args[]) {
      // Stream to read file
      FileReader fr;
      FileWriter fw;
      Collection<String> lineStorage = new ArrayList<String>();
      String line = "";
      boolean finishedRemoving = true;
      final String filePath = "b.xml";
      try {
         // Open an input stream
         fr = new FileReader(filePath);
         // Read a line of text
         BufferedReader br = new BufferedReader(fr);
         while (br.ready()) { //while there's another line
            line = br.readLine();
            if (line.compareToIgnoreCase("  <app>") == 0) {
               finishedRemoving = false;
               continue;
            } else if (line.compareToIgnoreCase("  </app>") == 0) {
               finishedRemoving = true;
               continue;
            if (finishedRemoving) {
               lineStorage.add(line);
         // Close our input stream
         fr.close();
         fw = new FileWriter(filePath);
         BufferedWriter bw = new BufferedWriter(fw);
         for (String aLineStorage : lineStorage) {
            bw.write(aLineStorage);
            bw.newLine();
         bw.flush();
         fw.close();
      // Catches any error conditions
      catch (IOException e) {
         System.err.println("Unable to read from file");
         System.exit(-1);
}

Similar Messages

  • Opening edited files on Epson P-2000

    Had something unusual happen. Am using Elements 4.0 and CS2 as my "external" editor. Edited some pictures like usual....Elements renamed them to "....-edited... etc. like usual and put it in a version set with the original.
    Copied some of these edited jpg files to my Epson P-2000 and when I tried to open them I got an error message saying FILE EITHER CORRUPTED OR FORMAT NOT SUPPORTED.
    Anyone have any experience with this?
    Thanks.
    Gary

    Colin,
    the Epson P-2000 is a multimedia strage viewer.From thr Epson site - It supports JPEG and select RAW image files, MPEG4 and Motion JPEG video files, plus MP3 and AAC audio files.
    Gary,
    I did not see any info on what formats of file names the P-2000 supports. Does your owners manual have that info?
    Two things you might try to check if it is the file name-
    Do a File > Rename or a File > Export with the renaming choice for a few files that failed. OR When you do an edit, give the edited file a name that does not have the dash. See what your results are with those names.
    Barb O

  • Is there a way to open/edit files made with Microsoft Publisher on my new Mac?

    I recently upgraded to a Mac from a Dell and I have documents that I made with Microsoft Word and Publisher that I still need to be able to use with my Mac but I can't figure out how to open them with it. Is there a program that I need to download?

    Word documents from your PC will open directly in Word for the Mac. If you have the ability to save your Publisher documents from the PC in PDF format, they can be converted from PDF to Word format and emailed back to you by this web site, free of charge:
    http://www.pdftoword.com/
    Note that not all features of the resulting Word files will be as completely editable as they were in Publisher, but they should look pretty much the same and open easily on the Mac.

  • Downloads open as Text Edit files

    Hi, I bought my first Mac a couple of weeks ago (never been able to afford one before!) and it's proving to be as amazing as I expected, but I'm still trying to work lots of things out.
    When I try to download files from the internet or from email attachments they go to my downloads folder but when I open them they come up as what looks like a computer code in a Text Edit window.
    At first I thought this was because I was trying to open Windows only file types but I just tried to download a game that was supposed to be for Mac only and it happened here as well. (This is the website I was trying to download from: http://absolutist.com/mac/bubble_shooter/ )
    I appreciate I'm probably being a moron but I've trawled the forums here and can't seem to find an answer - any help would be very welcome.
    Thanks

    To The Apple Discussion Boards!
    After you click on the download link a window will pop up showing you what type of file it is you are trying to download. In this case, it's a .sit file.
    In the center of the window you will see:
    _*Open With.*_ Make sure this is selected.
    Now check to see what application/program is selected to open your files. It appears to be some text edit program. You will need to select an application that you want to open your .sit files or all your files for that matter.
    I personally, use the free Stuffit Expander to open all my files instead of depending on the OS to open them.
    You can download Stuffit Expander from VersionTracker.

  • I am working in text edit and cannot open my file. Error message says it is in the wrong format, truncated or corrupted. what to do?

    I am working in text edit and cannot open my file. Error message says it is in the wrong format, truncated or corrupted. what to do?

    Try opening Disk Utility in your Applications-Utilities folder and repair permissions.

  • I just downloaded Digital Editions to use an e-book I purchased.   When I try to open the file it opens in Adobe Reader and I get an error message.  Please help

    please help  I downloaded Digital Editions to use e-book and when I got to open I get an error message

    It says file could not be opened because it was either not a supported type or it was damaged.  I have already had the file resent and in talking to the American Medical Association (purchased from their site)  it appears when I go to open the file it is in Adobe Reader and I do not see an option to move it to Adobe Digital Editions,
    Kathy Harlan
    <mailto:[email protected]> [email protected]
    Cell: 214-850-6427

  • I have an old mpg video file, taken with a very early model "smart phone", that opens and plays fine in my newly "rebuilt" iPhoto library. I cannot open, edit it or share it with any other software. How can I fix it, to be able to do anything with it?

    I have an old mpg video file, taken with a very early model "smart phone", that opens and plays fine in my newly "rebuilt" iPhoto library. I cannot open, edit it or share it with any other software. How can I fix it, to be able to do anything with it?
    Detail:
    I've recently purchaced a 4TB Thunderbolt drive to store my "vast" music and photo libraries. iPhoto had an issue reading the moved library, so I bought and used iPhoto Library Manager to "rebuild" it. Apart from much of the original data such as date taken & camera used etc, it appears to be working well. The aforementioned mpg video was taken some 9 years ago, using an early model "iMate" smart phone, and opens and plays fine on iPhoto, but I cannot open it with anything else, (I've tried iMovie, VLC players, Wondershare and Handbrake) nor can I share it. I just want to edit it, and share it with family.
    Any help would be appreciated...

    No - not iMovie, VLC, Wondershare or Handbrake... Quick time starts with a "CONVERTING", then I get
    I've looked at the "tell me more" links, tried downloading some of the movie players there. I'm begining to think the file is corrupt.
    Thanks for getting back to me again though - appreciate it...

  • I am trying to delete pages from a PDF file. I opened the bookmarks, selected the pages to delete and choose Edit Delete. The selected pages are not deleted. Note: I have to open the file using a passport provided by an external party.

    I am trying to delete pages from a PDF file. I opened the bookmarks in the PDF file, selected the pages to delete and choose Edit > Delete. The selected pages are not deleted. Note: I have to open the file using a passport provided by an external party.

    Resolved

  • I tried to change the file type of the movie, but now I am unable to open/edit it in iMovie, HELP !

    I tried to change the file type of the movie, but now I am unable to open/edit it in iMovie, HELP !

    Thank you very much! This is exactly what I was looking for.
    I appreciate your time and effort in solving my question : )

  • I am not able to use Firefox with Sharepoint - I can only open a file in read-only mode and cannot checkout the document and edit.

    I would like to use Firefox with Sharepoint.
    However, I am only able to open a file in "read only" mode whch means I cannot edit the document and save it. I am also not able to "check-out" a document in Sharepoint and edit it at the same time.

    This may not work for everyone, but I solved this problem by clicking on the file name in sharepoint, not the document icon to the left of the name. This then brought up the various options, including checking out, editing, version history etc. It seems obvious but I have only just realised this!

  • I would like to be able to edit MP4s in CS5.  I can not open the file. What am I missing?

    I would like to be able to edit MP4s in CS5.  I can not open the file. What am I missing?

    According to the publisher For GoSystem Tax, the 32-bit version of Internet Explorer 8, 9, or 10 is required.  Which means it can't be accessed from an iPad.  This seems weird.  I would recommend you contact the publisher.

  • I open a file - playback - the audio is there - doesn't appear in timeline, but I hear it, after 1 edit, the audio disappears.  I have to reboot to get it back then it happens again.  All suggeswtions welcome.  Thank you, Randy

    I open a file - playback - the audio is there - doesn't appear in timeline, but I hear it, after 1 edit, the audio disappears.  I have to reboot to get it back then it happens again.  All suggeswtions welcome.  Thank you, Randy

    Is your Premiere Elements 12/12.1 running on a Windows 7, 8, or 8.1 64 bit computer or a Mac computer?
    What is the brand/model/settings of the camera recording your video?
    Windows 7 64 bit PC 
    Footage taken from DVD through Adobe Premiere Elements
    Are you sure about the Frame Width and Frame Height that you gave 720 x 484? Did you mean 720 x 480?
    Yes, my err.  720X480
    For the Frame Rate, was it really 29.97 frames per second and you rounded it off to 29 frames per second? Or,
    is the frame rate really 29 frames per second?
    If the properties that you just posted are representative of your source file, what project preset did you or the
    project set for the project preset? If you are not sure, please tell us the readings for Editing Mode, Timebase, Frame Size,
    and Pixel Aspect Ratio under Edit Menu/Project Settings/General.
    Still having problems - haven't been able to edit project. 
    Thank you for your help.
    Randy Klein

  • Can I open .ai file w/ text editor and edit linked file path?

    I want to relink a placed file in a lot of illustrator files to a new file with a different name. I've tried setting up various actions but it is not doing what I need. If I open the file in a text editor such as Notepad++ or Text Wrangler, I can find the linked file path in two places, if I edit this path and save the file (still with .ai extension) I thought the link would change, but when I reopen the file, it does not change. Any ideas?
    If I make an action to relink a file, the action will only place a new file but not replace the old one. I also can't get it to place into a specific layer.
    Any ideas?

    CSS files are plain text with no links, so what you see is all there is.
    In order to apply CSS to HTML, you need a &lt;link> tag in your HTML.
    If you install the Web Developer Extension from the Firefox add-ons site, there is a handy "Edit CSS" sidebar that lets you play with style rules and see the effects live. Note that this pane is not saved, so if you switch tabs, you lose your changes. Make sure to copy out any changes you want to remember.

  • SharePoint 2010 and PowerPoint 2010: Open PPTX File in Edit Mode and Open PPSX in in Slide Show Mode

    I have the following issue while opening PowerPoint PPTX file and PPSX from the Document ID link provided by SharePoint 2010.
    Issue
    Initially when I opened PPTX file from the DOC ID link from SharePoint 2010, it is opening up in Slide Show mode which is not how we want it to be.
    For PPSX, it is opening in Slide Show mode which is what we wanted.
    Thus, I did some research online and found this article at support.microsoft.com/kb/q299824  which requires some modification to the Registry of the client machine.
    I did the change as follows
    Open Registry
    Look for “Computer\HKEY_CLASSES_ROOT\PowerPoint.Show.12”
    Set BrowserFlags value to a
    After the change, PPTX is opening in Edit Mode in PowerPoint which is correct but PPSX is also opening in Edit Mode in PowerPoint which is not correct
    This issue only occurs if I open the document from the Doc ID link in SharePoint. If the documents are downloaded, it will not have this issue.
    Questions
    Can I set PPTX to open in Edit Mode and PPSX to open in Browser Mode?
    Is this fixed as in if I change the registry setting it will affect both file types?
    Is there other ways I can achieve opening PPTX in Edit and PPSX in Browser Mode?
    [Environment]
    My Client machine is running on I.E 9 and Office 2010.
    Thank you.

    Hi,
    To make the PPTX file open in Edit mode and PPSX file open in Slide Show mode, I recommend to edit the registry key HKEY_CLASSES_ROOT\PowerPoint.Show.12 to 8.
    I tested the scenario in my environment with changing the key value to 8, after that PPTX file opened in Edit mode and PPSX file opened in Slide Show mode.
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • DW won't open PNG file to edit in Fireworks

    I have a complex Fireworks file inserted as part of my html page. I'm trying to edit and update it from Dreamweaver, but it will not open the file in Fireworks.
    It's a png file that has been updated from an older version of Fireworks, but I've done a save-as and re-exported the slices and html, then re-inserted it into the page. It still will not open the file in Fireworks.
    As a test, I created a new png file, exported it, inserted it into the html page, then tried to edit it in Fireworks. And that does allow me to edit, click done, and then the changes show up on the html page. So it's something with my original file, but I can't figure out what it might be.
    Does anyone have any suggestions on how to get this working?
    Any help will be greatly appreciated.
    Thanks.

    Can you open images normally in Photoshop Elements?  I would recommend including this information as well as which verson of iPhoto and Mac OS you are using to the Photoshop Elements forum.  It might also possibly be a problem with iPhoto but the users in the Photoshop Elements forum should better be able to determine where the problem lies.

Maybe you are looking for

  • TVSU 4.03.0012 no longer works for 4713CTO

    Hi The recent update of TVSU to 4.03.0012 appears to have broken support for my 4173CTO. The relevant message from the TVSU log file shows that a 4173CTO is no longer considered a Lenovo system! Info 2012-05-23 , 11:49:07  at Tvsu.Engine.Process.Hell

  • Connection limits questions.

    Hi all. i got a crahed 5520 this week and was showing <163>Nov 28 2011 11:34:45: %ASA-3-201013: Per-client connection limit exceeded -125/100 What the negative number tells ?  i usually see same numbers like 100/100 with means the connection limited

  • Getting authorization

    My pc keeps asking me for authorization. I've follow the steps to repare it.But unfortunately it doesn¡t work. Any advice? Many thanks

  • SC Approval mail Language - other than mentioned in Offline report

    Hi All, I have an issue with the approval mails. In the offline approval /SAPSRM/OFFLINEAPPROVALSEND email language was set as English. However system is sending mails with user local language. Like if user belongs to germany then mail was triggered

  • Time Machine Backup Disrupts Streaming to ATV2

    Here's my latest disappointment with ATV2. Because of unreliable internet streaming of rented TV shows from iTunes, I have begun downloading them to my computer and then streaming to my ATV2 using only my home network. Mostly this has worked well. Ho