Updating a file with new input

Hi. How would I be able to read in a file, and than update that same file with input from the user? Example: I have a file named 'Num' with the numbers '1','2', and '3' in it. How could I read those three numbers in, and than update it the file with something the user puts in, like '4'? Thanks.

import java.io.*;
public class ReadAndUpdateFile
  public static void main(String args())
    throws Exception
    new ReadAndUpdateFile(args(0));
  } // main
  public ReadAndUpdateFile(String file)
     throws FileNotFoundException, IOException
    String line = null;
    BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
    while ((line = br.readLine()) != null)
      System.out.println(line);  // dump each line
    br.close();
    System.out.println("Enter your number:");
    br = new BufferedReader(new InputStreamReader(System.in));
    line = br.readLine(); // Get User Input
    boolean append = true;  // True means that it will append to the file
                            // if it exists and create it if it doesn't
                            // set to false it will overwrite it with a new file
    FileOutputStream fos = new FileOutputStream(file, append);
    fos.write(line.getBytes());
    fos.flush();
    fos.close();
  } // ReadAndUpdateFile
} // ReadAndUpdateFileOK... this gives you a VERY good idea... read the javadocs to understand it
PS I didn't compile it... so it may not compile.. but it is VERY close...

Similar Messages

  • Update jar file with modified class files

    hi all,
    I'm developing a jar utility for updating a jar file with modified class files as of now i have reached a point where in i can browse files and set it to required location
    i.e i have developed a swings GUI application using JfileChooser and browse the files ..now my requirement is to update the jar files with modified class file
    GUI looks like below
    ....enter the modified class file ----> d:\c.class
    ....enter the jar file path ---> d:\a.jar
                                                          update button now i have the requirement as
    1> when i click on the update button ,my jar file (a.jar) should get updated with the latest class file (c.class)
    can u help me to achieve this requirement.???
    im stuck with this,,,if u can provide me wit the code for updating jar file with latest class file...it will really be helpful
    if u can help me with the code on click on update button it will be really helpful
    Thanks and expecting a faster response from u all java experts....

    Please find my query in bolds...i have written the partial code now,i need some help now
    hope u guys can help me out...
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.File;
    public class FileExplorer extends JDialog implements ActionListener
         JTextField txtLocation_class;
         JButton btnBrowse_class;
         JLabel label_class;
         JTextField txtLocation_jar;
         JButton btnBrowse_jar;
         JLabel label_jar;
         JButton updatebutton;
         public FileExplorer()
                   setSize(600,300);
                   //for class files
                   label_class = new JLabel("Please select Modified Class File");
                   txtLocation_class= new JTextField(20);
                   btnBrowse_class = new JButton("Browse");
                   btnBrowse_class.addActionListener(this);
                   //for jar files               
                   label_jar = new JLabel(" Please select the Jar file");
                   txtLocation_jar= new JTextField(20);
                   btnBrowse_jar = new JButton("Browse");
                   btnBrowse_jar.addActionListener(this);
                   ActionListener updateListener = new ActionListener(){
                    public void actionPerformed(ActionEvent ae){
                     if(ae.getActionCommand().equalsIgnoreCase("Update")){               
                      System.out.println("ae.getActionCommand() :: "+ae.getActionCommand());
                      System.out.println("Update Button is pressed");               
                    *//Query :how do i access FilePath and FilePath1 here which*
    *                // has been set in public void actionPerformed(ActionEvent ae)*
    *                //method below*
    *                // FilePath  ---??*
    *                // FilePath1  ---??*
    *                // how do i access the above 2 parameters*
    *                //Query :on click of update button i have to pass*
    *                //two parameters FilePath and FilePath1 to*
    *                //perform some functionality. please help me*
    *                //to achieve this..how do i access Filepath and Filepath1*
    *                //here which has been set below.*
                     } // end of if               
                   } // end of actionPerformed
                };// end of ActionListener
                  updatebutton = new JButton("Update");
                  updatebutton.addActionListener(updateListener);
                   //adding to the panel               
                   JPanel pnl = new JPanel();
                   pnl.add(label_class);
                   pnl.add(txtLocation_class);
                   pnl.add(btnBrowse_class);
                   pnl.add(label_jar);
                   pnl.add(txtLocation_jar);
                   pnl.add(btnBrowse_jar);
                  pnl.add(updatebutton);
                   getContentPane().add(pnl);                         
         public void actionPerformed(ActionEvent ae)
              Object obj=ae.getSource();
              if(obj==btnBrowse_class)
                   final JFileChooser fcstudent = new JFileChooser();
                   int rtrnval = fcstudent.showOpenDialog(this);
                   if(rtrnval==JFileChooser.APPROVE_OPTION)
                        try
                             File file=fcstudent.getSelectedFile();                         
                             String path = file.getPath();
                             System.out.println("This is Path:"+path);
                             txtLocation_class.setText(""+path);
                             String FilePath=txtLocation_class.getText();
                             System.out.println("FilePath is ::"+FilePath);                                        
                        catch(Exception ex)               
                             ex.printStackTrace();
              }else if(obj==btnBrowse_jar){
                             final JFileChooser fcstudent = new JFileChooser();
                             int rtrnval = fcstudent.showOpenDialog(this);
                             if(rtrnval==JFileChooser.APPROVE_OPTION)
                                  try
                                       File file=fcstudent.getSelectedFile();                         
                                       String path1 = file.getPath();
                                       System.out.println("This is Path:"+path1);
                                       txtLocation_jar.setText(""+path1);
                                       String FilePath1=txtLocation_jar.getText();
                                       System.out.println("FilePath is ::"+FilePath1);                                        
                                  catch(Exception ex)               
                                       ex.printStackTrace();
         public static void main(String arg[]){
                   FileExplorer Exm= new FileExplorer();
                   Exm.setVisible(true);
    }

  • I want to update iCloud account with new apple id but don't know password for old apple id.  Plus can no longer receive email at old apple id.  How can I delete the current iCloud account on my iPhone if the previously stated conditions exist?

    I want to update iCloud account with new apple id but don't know password for old apple id.  Plus can no longer receive email at old apple id.  How can I delete the current iCloud account on my iPhone if the previously stated conditions exist?

    If the old ID is yours, and if it is an earlier version of your current ID, go to https://appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Click edit next to the primary email account, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iDevice, even though it prompts you for the password for your old account ID. Then save any photo stream photos that you wish to keep to your camera roll.  When finished go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https://appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • I have updated my Iphone5 with new IOS6 - now the screen/display does not react to my taps on screen as in i cant tap in my pin to start???

    I have updated my Iphone5 with new IOS6 - now the screen/display does not react to my taps on screen as in i cant tap in my pin to startup???

    I have updated my Iphone5 with new IOS6 - now the screen/display does not react to my taps on screen as in i cant tap in my pin to startup???

  • [svn:osmf:] 13083: Updated MASTAdapter class with new trait names and events.

    Revision: 13083
    Revision: 13083
    Author:   [email protected]
    Date:     2009-12-17 16:10:05 -0800 (Thu, 17 Dec 2009)
    Log Message:
    Updated MASTAdapter class with new trait names and events.
    Modified Paths:
        osmf/trunk/plugins/MASTPlugin/org/osmf/mast/adapter/MASTAdapter.as
        osmf/trunk/plugins/MASTPluginIntegrationTest/src/org/osmf/test/mast/TestMASTPluginInfo.as
        osmf/trunk/plugins/MASTPluginIntegrationTest/src/org/osmf/test/mast/adapter/TestMASTAdapt er.as

    Silviu!
    I'm really sorry, but as all the office is trying to fix the problem, someone replaced the url content with the stuff that was pointing to the local machine.
    I've fix it, and the video player is available here again: http://pp.player.webtv.flumotion.com/params/apiKey/5PzLR2ULL3z2rumJ/videoId/60
    If there are other references to the localhost, please do not bother with them, as they do not affect player functionality.
    The stream that it uses is an RTMPE, so i'm afraid it will only works with this player. Anyway, the stream url is as follows: rtmpe://87.248.205.81/a4349/e2/veo7/ondemandrtmpe/mp4/med/first-person-mario-4d8741aa.mp4
    I really appreciate your help!
    Thank you!

  • HT1311 How can I get updates for apps with new Apple ID

    How can I get updates for apps with new Apple ID. I have apps that I got for free, and some that I have purchased. I had to create a new Apple ID because I don't have a credit card now.

    Apps will always be tied to the ID in which they were purchased or downloaded under. You can not change this unless you buy or download the free  app using the new ID.

  • HT1414 When updating my iphone with new software it came up on screen with the cable and itunes sign (which is what I should get when restoration has been completed) yet it is still saying restore. I have tried 3 times and the screen won't change. HELP!

    When updating my iphone with new software it came up on screen with the cable and itunes sign (which is what I should get when restoration has been completed) yet it is still saying restore. I have tried 3 times and the screen won't change. HELP!

    If the sign does not go away it has not completed the restore. So you are incorrect when you say it "keeps completing the restore" if that message is still displayed.
    Do you get an error message? If so, what is the error number?

  • Save NI report generator files with new names

    I was trying to save labview library files under new names so that I could adapt the code but the 'Save As' option is greyed out. In certain cases, when I try to copy and paste the code, I get broken wires and cannot get the VI's to work.
    I have been using the report generator toolkit which is quite limited. I was trying to delete a row from an spreasheet but there is no function to do this. So, one workaround that was suggested to me was to use the 'Excel Insert Cells' VI and change the code to instruct it to 'clear' cells rather than 'insert' them. This works, but I wanted to save a copy of the amended file under a different name so that it was independent of the installed library files but I can't seem to do this. I tried to copy out the code but got broken wires even though I have been able to do this in other instances.
    Any suggestions?
    Thanks,
    Will

    Hi Will,
    I had the same problem with a project and found the following workaround:
    To ensure the original function of any library VI, it's not recommended to just change the VI to do something else.
    Therefore I expanded the VI to do both, the original functionality and the special function I needed.
    I made an extra Input to the VI, which is a boolean Input.
    With that extra optional Input I can now choose the function I want to do.
    I made the "False" case to be default. This case works like the original function.
    The "True" case is built to do my special function.
    This workaround is quite easy and not dangerous. For all projects, which would use the function in their normal use case it's working just as if the file was unchanged.
    And for projects using special functionality I can add a "True" constant to my VI Input and the function works as I want..
    Hope this workaround helps to fix your problem!
    Kind regards
    adigator

  • REUSE_ALV_GRID_DISPLAY - updating the database with new values

    Hi,
    I am using the function module 'REUSE_ALV_GRID_DISPLAY' to display records. I have managed to open a field for input/edit mode. Once this data has been changed , where will this data be? I have checked the internal table - no joy. I need to use this new/changed data to update the database with the new values.
    Thanks,
    Leanne

    Hi,
    The data is stored in table tab. After the changes the data does not reflect in table tab. Where can I get the data so that I can update my database?
    I have coded the process as follows:
        when '&SUSPEND'.
          loop at tab
            where box = 'X'.
              update zzzz
                set status       = 'SP'
          endloop.
    Regards,
    Leanne

  • Replace files with newer download files on NB100?

    Just got the NB100 for my daughter and we both love it to bits:)
    I'm doing the update and it's found 129 updates and after downloading, it's asking me at various points if I'd like to keep a modified file or replace it with the newer downloaded file.
    What do I do?
    Homey

    I just went ahead and replace everything with newer versions and everything worked apart from the sound. two lines of typing at the terminal screen fixed this and everything now works!
    Hope this is of help to anyone who's bought oneof these babies!
    Homey
    Still learning...

  • How to correctly update .indd files with incopy through adobe cc

    Hello,
    We have a group of users in our company that only have incopy. This is done both for a control (no one changes layouts by accident) and for cost savings of not haveing the full suite for every user.
    With this environment we have found that...
    After any change to text via incopy, a person with adobe InDesign will need to open the file and update links so the .indd file will reflect the text changes.
    This will need to happen after proofing or any other editorial changes along the way. This adds many steps to our workflow.
    Ex:
    Alyssa is editing a sustainability article with incopy (no indesign). She makes her edits and save the contents (copy fits, remove a punctuation etc). However, when viewing the .indd file in adobe CC, her changes are not reflected.
    Bill (indesign user) had to open the file with InDesign, click update links (this is a popup box upon opening) and then save the file again, before the file would reflect the text changes.
    Does anyone know of a way to get around this? It would be great if incopy could push the text changes to the .indd file without a seperate step.
    Thank you,
    Andy

    I'm a little confused. Are the InCopy users using InCopy to edit standalone files (they're opening ICML files)? Or are they opening up the INDD file (the layout) in order to edit the stories context of the design.
    If the latter, then there's no need for the InCopy user to wait for an InDesign user to do something. As they make their edits in InCopy, the layout view in InCopy gives them a pixel-accurate preview of how their changes will appear in the final layout. If other InCopy users are editing different stories in the same publication (layout), any user can update to view their colleague's edits on a story-by-story basis, or all at once.
    And when an InCopy user sits down to work and opens a layout from the server, InCopy automatically makes sure that they are seeing the current versions of all stories in the layout ... they don't get prompted to update the stories, it happens by default. Even if the InDesign user hasn't touched the file or updated the stories.
    FWIW, most of my InCopy/InDesign clients use this layout method.
    AM

  • Update book inventory with NEW company code assignment for the same site

    Hi gurus ,
    Our company have this business scenario:
    the site has run in Company Code A for several month with business of Material Management  function, then the site have to be changed to Company Code B for financial requirement .
    What we want is we change the CC assignment by OX18 for site master without changing the site number (creating a new site master ),except for the open purchasing or  sales document clearance , is there any way we can update the book inventory  with new profit center corresponding to the CC B ?
    Thanks in advance ,
    Ryan

    Actually we have made some discussion with SAP consultant about this requirement ,and they suggest the same thing ,but for many reasons ,we need to make it that way ,and we also made some test for this direct changing by OX18  for new CC assignment .
    All other questions are  under control now , for financial reason ,we need to update the book inventory to new CC assignment (new profit center after site-specific material master changed ) in some batch session or program ,any idea for this?

  • Viewing a pdf file with new and new content

    Hello folks,
    Assume that one creates a pdf and uses Preview or Reader to view it.
    Then adds something to the picture and opens the file again: new content, old filename.
    One would like to see one of the following schemes:
    a) Open would close the old window and present the new content in a new
    window.
    b) Open would keep the old window and create a new window for new content.
    What happens is:
    c) Open says: "I've already displayed a file with this name, I don't need to do a thing."
    Is there a way to force behaviour a) or b) ?
    Thanks,
    Miklos

    If the mountain does not come to Muhammad, then Muhammad goes to the mountain.
    On this basis I wrote a short perl script that increments a number, and constructs a new
    filename from the original filename and the incremented number.
    Then it copies the original file to the new name and runs Reader or Preview on the new file.
    Now I can see as many versions together as I like.
    Miklos

  • Merge Illustrator cs4 file with new document

    Hi all,
    I recently got an 'unknown error has occured' with a file I have been working on in Illustrator CS4.  I remember there was a way where you could open a new Illustrator document and drag the file with the error into the new document, but from there I do not know how to merge this in where we can get back the layers and objects from the file with the error unto the new file.  Does anyone have some instructions on how to merge the document in?  Thanks in advance.
    pwitman

    Hi,
    I tried saving the file into a PDF after opening it up in Acrobat, but I got this error when trying to save "The document could not be saved.  There was a problem reading this document (109)."  But when I drag the file into a opened new document in Illustrator cs4, it would load up, however I don't know the steps to merge or group the objects and layers back into the new document.  Could anyone provide me the steps on how to do this?  Thanks.
    pwitman

  • Will Windows Phone AppData change/Deleted if I update.aapx file with .xap in to the store

    I created an universal Windows Phone application using c# xaml that have user information in the appdata 'Local'
    folder.
    And I published it in to store. But due to some performance issue I forced to move on to silverlightfor
    updating the application.
    So I need to update package .appx file
    with .xap file.
    Is that possible ? Will it delete data from Local app folder of the current user ?
    anoop m

    Hi,
    you cannot downgrade a published app with version 8.1 to version 8, and you cannot downgrade an AppX Bundle to an Appx Package, or an Appx package to a XAP package.
    You could updated it with a Windows Phone Silverlight 8.1 app.
    After the updated, during the first access you could remove all data stored in Local Storage.

Maybe you are looking for

  • DVI vs. Analog connection

    I just got a new monitor that has both Analog, and DVI hookups. I am currently connected using the Analog, because that is what cable came with the monitor. My G4 tower also has a DVI & Analog connectiosn. Is it worth getting a DVI cable to connect t

  • Transaction Summaries in Inventory module Transactions

    In Inventory module -> Transactions -> Transactions summary. The user selects a particular date range and an item number. When the summarize button is clicked, a screen populates with list of source type. How does Net Qty,Net Value and Net Volume,ABS

  • How can i turn off find my iphone without a password

    I have a I phone 4 last week it just stop working no internet But i still have 3 bars at the top i can still use facebook  no moving post i cant log in to anything i thought it had been blocked cant face time cant reset back to factory settings can r

  • ABAP Books

    Hi, I got a second hand ABAP Book called: Introduction to ABAP/4 Programming for SAP.  I did not realize that this book was 10 years old, until after I bought it.  How much has ABAP changed since 1998?  Should I refer to this book, or is it useless?

  • Why are some of my fonts no longer working?

    SInce upgrading to Snow Leopard, I have noticed that many of my previously working fonts no longer work. Is there some kind of incompatibility font bug that was introduced with Snow Leopard? Has this been addressed in Lion? If not, how do I get my fo