Open and modify an existing file in java

Supposed I have a file called myfile.txt, its content is below:
XYZT.....
...keyword: mykeyword
ABCD.....
I would like to open it, go to the "keyword", modify the string "mykeyword" to "changedkeyword" then save the file. Note that I want to save the change to the file, not to create another file. What should I do?
Now I know many of you will suggest me reading I/O classes. I know I/O classes but still couldn't find what I want. A simple source code would be great.

Okay then. If the word is the exact same size, then simply locate it and write the new word. Thats one optimization.
Another is to read until you find the word. Then read a buffer of size n+(replacement.length-original.length). Write the replaced word, then the buffer and continue until done.
How big are your files and how many of them and how timely do you have to be in this operation?

Similar Messages

  • HT4753 would number automatically save an .xlsx file I opened and modified but not saved? I've lost a file with many edits...

    would number automatically save an .xlsx file I opened and modified but not saved? I've lost a file with many edits...

    kearly - thanks a million for posting both the question & the reply! I just unchecked that little box by accident, & couldn't figure out for the life of me how to fix it. Thanks again!!

  • How do i open and modify my pdf converted to excell spreadsheet

    How do I open and modify my PDF converted to Excell spreadsheet?

    After the conversion from PDF to .xlsx, you should be able to open the file in Excel and edit it like any other Excel file.

  • Illustrator CS4 opens fine but cannot open any new or existing files

    Hi guys,
    I'm running Adobe Illustrator CS4 on my Mac Pro running OSX 10.7 Lion and for some reason I am no longer able to open any new or existing files. Illustrator boots up just fine but 'File>New' gives me nothing. 'File>Open' gives me my usual search box but once a file is selected, again, I get nothing. Dragging a file into Illustrator gives me this response',
    before promptly quitting.
    I have tried deleting all the files from my Illustrator Preferences folder but doesn't seemed to have helped.
    Any advice on this would be greatly appreciated.
    Thanks in advance.

    You could be out of luck. See Scott Worthington's post here: http://forums.adobe.com/message/4844260#4844260

  • TS1368 I'm a PC user with an itunes account for several years. I updated my itunes and now it wont open and shows me 'missing file MSVCR80.dll,and error 7(Window error 126)' keep coming up even after re-installing itunes . What should i do?

    I'm a PC user with an itunes account for several years. I updated my itunes and now it wont open and shows me 'missing file MSVCR80.dll,and error 7(Window error 126)' keep coming up even after re-installing itunes . What should i do?

    Click here and follow the instructions.
    (98897)

  • How to open and validate the tif images via java?

    Is it possible to open and validating the photoshop images via java. Kindly advise me.
    Thanks for looking into this.
    Maria Prabudass

    I have recently looked at athe code for Image Processor.
    To avoid bailing on errors it uses two techniques.
    1) It turns off all PS error reporting in addition to just turning off dialogs with:     app.displayDialogs = DialogModes.NO;  (it restores the original settings when exiting)
    2) It uses the Javascript construct  Try.....Catch around the basic body of the code so "any" error will not abort the script but just jump to the "Catch" code.
    Hope that is useful

  • Hi... I would like to purchase a Tablet Sony Xperia Z 2 10.1 (the last one of the Z series) and I was told that Adobe does not support Sony anymore.... I need to be able to open and read Adobe PDF files and I would like to know if this tablet can still us

    Hi... I would like to purchase a Tablet Sony Xperia Z 2 10.1 (the last one of the Z series) and I was told that Adobe does not support Sony anymore.... I need to be able to open and read Adobe PDF files and I would like to know if this tablet can still use Flash Player...
    Is there anyo who can help me with this? I asked in the shop and I was told "yes of course" , but when I contacted Sony directly I was advised to check with Adobe as apparently in the recent months Adobe and Sony haven't been getting along anymore...

    You may be mixing up two entirely different Adobe products.
    1. Adobe Flash Player. Needed to view web pages designed with Flash. Not needed to view PDF files. Not available for Android (not just Sony).
    2. Adobe Reader. Reads PDF files. However, the Android can also read most PDF files without needing Adobe Reader.

  • How to create and edit a .ini file using java

    Hi All...
    Pls help me in creating and editing an .ini file using java...
    thanks in advance
    Regards,
    sathya

    Let's assume the ini file is a mapping type storage (key=value) so lets use Properties object. (works with java 1.4 & up)
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Properties;
    public class Test {
         private static Properties props;
         public static void main(String[] args) throws IOException {
              File file = new File("test.ini");//This is out ini file
              props = new Properties();//Create the properties object
              read(file);//Read the ini file
              //Once we've populated the Properties object. set/add a property using the setProperty() method.
              props.setProperty("testing", "value");
              write(file);//Write to ini file
         public static void read(File file) throws IOException {
              FileInputStream fis = new FileInputStream(file);//Create a FileInputStream
              props.load(fis);//load the ini to the Properties file
              fis.close();//close
         public static void write(File file) throws IOException {
              FileOutputStream fos = new FileOutputStream(file);//Create a FileOutputStream
              props.store(fos, "");//write the Properties object values to our ini file
              fos.close();//close
    }

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • How can I create an icon that when clicked will open and maximize an image file?

    How do I create a icon that when clicked will open and maximize an image file?  I have tried to use the simple image widget with maximize upon tap/click - however I am can only size the image really small and put on the page.  I'd prefer to have a graphic that when clicked it simply opens up the image.  This is for a very simple question/answer book.   The user is suppose to look at a picture and locate something.  I want to put an 'Answer' graphic on the image and then the user can click the 'answer' graphic and it will open up the picture with the answer identified. 
    Is this possible?

    Have yiu tried the PopOver widget?  You can drop an image into it, maximise the image and the widgets window...But, you cannot get it full screen.
    With iBooks Author, you either learn to use what is available within the app, or look online for third party widgets to purchase which suit your project.

  • Can you please make an update to open  and show itunes photo files on the computer as well as devices ????????? PLEASE?????????

    Can you please make an update to open and show itunes photo files on the computer as well as the devices ??????? PLEASE????????????? It's a real pain to view old photos for time and capacity reasons!!!!

    You seem to think you are talking to Omnifocus here.  The odds of actually reaching them here are practically 0%, I would guess.
    I suggest you go to the omnigroup forums and present your suggestions in the omnifocus forum.
    http://forums.omnigroup.com

  • I need to open and use a DFX file in Illustrator CS6 only displaying digits and letters

    I need to open and use a DFX file in Illustrator CS6 but it is only displaying digits and letters as opposed to fashion patterns. I believe the original file was  created in Gerber

    Thank you.
    I will see if I can access/download a CS2 version. Thats a kind offer, I will see how I go with the download first, as I will be needing to open several files over the next few weeks.
    Maxine

  • What apple software allows me to open and work with excel files?

    What Apple software allows me to open and work with Excel files?

    Numbers, OpenOffice, Microsoft Office 2008 or newer, or similar products. Microsoft Office 2004 doesn't work in 10.7.
    (86805)

  • How to open an existing file from java

    Hi Guys,
    I have one problem Please help me in this.
    How to open file(i.e. file can be any type, it is may be image file, doc file or pdf file) using java.
    Even i tryed in one way but it is static way that is working in windows not for other OS.
    Code :
    import java.io.*;
    public class CmdExec {
    public static void main(String argv[]) {
    try {
         DataInputStream din=new DataInputStream(System.in);
         System.out.println("Enter File Path to Open");
         String fName=din.readLine();
         File file=new File(fName);
    Runtime.getRuntime().exec("rundll32 SHELL32.DLL,ShellExec_RunDLL " + file.getAbsolutePath());
    catch (Exception err) {
    err.printStackTrace();
    If any other way to do please tell me.
    Regards
    Siva Prasad

    Well, if the OS doesn't provide a mechanism to associate a file name with a certain program, there's nothing you can do.
    I don't know whether something like JDIC can help you - otherwise, you'd have to find the solution for each OS. What's inside the exec()'s parenthesisses is not a Java problem anymore.

  • How to open and modify a internet service.

    I want to modify Internet Service PZ02. I checked in SICf, it is listed under bc/gui/sap/its and is also activated.
    But when i go to SE80 and search for it in Internet Service, i get a message saying "Service PZ18 does not exist, create object? "
    How do i open, get access to code of pz18 and modify it
    Thanks
    Sharath

    Chris-
    Thanks for the reply.
    How do i create the ITS service (service file, template, theme etc..) out of the dynamically generated HR service PZ02.
    Pleae let me know if the following steps are correct
    1. In SE80, Choose Internet service and enter a name like zpz02.
    2. In the pop-up for transaction code enter pz02. Check the box for ITS mixed mode
    3. Then Right click in zpz02, select create->template->
    assign theme=99,
    program number-SAPMPZ02
    screen number=1000
    generating style=webgui
    ( The above informtaion was found out in the following way: go to se93 -> enter pz02 as the transaction code ->
    click display.
    When i did that it displayed the following info
    program : SAPMPZ02
    selection screen: 1000 )
    When i click on save it says that the screen 1000 does not exist in the program SAPMPZ02.
    But from the info that i got from the SE93 it looks like the screen number is 1000??
    What is the mistake ?? Is the approach wrong
    Help will be really appreciated
    Sharath

Maybe you are looking for