Update/delete text file - Urgent

hi guys, i have a text file. Using io package i would like to search a particular string in the file. when i got the search string either i have to update some text in that row or i have to delete the row. how can i do that. If any one tried pls let me know with code. Ur valuable suggestion are welcome.
thax in advance

An obvious method is to copy the whole file with the changes made into a temporary file .
After the operation delete the orginal file and rename the temporary file to orginal file.

Similar Messages

  • Bulk Data - Insert / Update from text file - Urgent

    hi,
    Consider there is a Table A. There are around 1.7 Million
    Records.
    i have a situation that i will be getting the Data,
    Every two Weeks, around 100 - 200 thousand Records.
    I have to do some calculations.
    If any Old Data Exists, then update the Data
    for the Non - Primary Key Fields.
    Else
    I have to Insert the New Data.
    Most of the time, i will be getting update information.
    very few hundreds, insert records.
    Please, help me, by providing the techniques or tools.
    Is it posssible to automate the whole process.
    Sreedhar V
    null

    Sreedhar V (guest) wrote:
    : hi,
    : Consider there is a Table A. There are around 1.7 Million
    : Records.
    : i have a situation that i will be getting the Data,
    : Every two Weeks, around 100 - 200 thousand Records.
    : I have to do some calculations.
    : If any Old Data Exists, then update the Data
    : for the Non - Primary Key Fields.
    : Else
    : I have to Insert the New Data.
    : Most of the time, i will be getting update information.
    : very few hundreds, insert records.
    : Please, help me, by providing the techniques or tools.
    : Is it posssible to automate the whole process.
    : Sreedhar V
    Here's a process that might help:
    create a temporary table the same format as the flat file.
    create a sqlldr control file to load the data from the file into
    the temp table
    create a pl\sql or JAVA script to cursor through the records
    from the temp table and for each row see if there is a match on
    TABLE A. If so this is an update, if not it is an insert.
    If you are in a Unix environment you can write a shell script to
    automate the whole process and schedule it in kron.
    null

  • JTable - Help with updating a Text File

    Hi all,
    I've been fighting this for a few days. I am trying to update a Text File with my JTable.... Displaying the data works great but when I try to edit a cell/field on the gui, I'm bombing out...... My text fiel is a small user control file with Id, Name,
    Date, etc etc with the fields delimited with a "|".... I have built an Abstract Data Model (see below).... and I think my problem is in the setValueAt method.......
    Thanks so much in advance!!!!
    Mike
    code:
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
    import java.io.*;
    import java.util.*;
    public class DataFileTableModel extends AbstractTableModel {
    protected Vector data;
    protected Vector columnNames ;
    protected String datafile;
    public DataFileTableModel(String f){
    datafile = f;
    initVectors();
    public void initVectors() {
    String aLine ;
    data = new Vector();
    columnNames = new Vector();
    try {
    FileInputStream fin = new FileInputStream(datafile);
    BufferedReader br = new BufferedReader(new InputStreamReader(fin));
    // extract column names
    StringTokenizer st1 =
    new StringTokenizer(br.readLine(), "|");
    while(st1.hasMoreTokens())
    columnNames.addElement(st1.nextToken());
    // extract data
    while ((aLine = br.readLine()) != null) { 
    StringTokenizer st2 =
    new StringTokenizer(aLine, "|");
    while(st2.hasMoreTokens())
    data.addElement(st2.nextToken());
    br.close();
    catch (Exception e) {
    e.printStackTrace();
    public int getRowCount() {
    return data.size() / getColumnCount();
    public int getColumnCount(){
    return columnNames.size();
    public String getColumnName(int columnIndex) {
    String colName = "";
    if (columnIndex <= getColumnCount())
    colName = (String)columnNames.elementAt(columnIndex);
    return colName;
    public Class getColumnClass(int columnIndex){
    return String.class;
    public boolean isCellEditable(int rowIndex, int columnIndex) {
    return true;
    public Object getValueAt(int rowIndex, int columnIndex) {
    return (String)data.elementAt( (rowIndex * getColumnCount()) + columnIndex);
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    Vector rowVector=(Vector)data.elementAt(rowIndex);
    rowVector.setElementAt(aValue, columnIndex);
    fireTableCellUpdated(rowIndex,columnIndex);
    // return;
    }

    No, the DefaultDataModel does not update the physical data file. It is just used to store the data as you type in the table cells.
    The code from above is used to read data from a file and populate the DataModel.
    Now you need to write another routine that will take the data from the DataModel and write it to your file. I have never actually done this but I think the code would be something like:
    int rows = table.getModel().getRowCount();
    int columns = table.getModel().getColumnCount();
    //  Write column headers
    for (int j = 0; j < columns; j++)
         TableColumn column = table.getColumnModel().getColumn(j);
            Object o = column.getHeaderValue();
         writeToFile( o.toString() + "|" );
    writeToFile( "\n" );
    // Write each row
    for (int i = 0, i < rows; i++)
        for (int j = 0, j < columns; j++)
            Object o = table.getValueAt(i, j);
            writeToFile( o.toString + "|" );
        writeToFile( "\n" );
    }If you need to update the file whenever data in a cell changes, then you could extend the DefaultTableModel and override the setValueAt() method to also write the contents of the DataModel to a file. But this is a lot of overhead since it rewrite the entire file for every cell change.

  • How to update a text file?

    I am doing an assignment about a bank account. A text file stores the accounts.
    Account Text file:
    User1|Password1|Balance1
    User2|Password2|Balance2
    When user wants to deposit or withdraw the account, then how can update the balance.
    The problem is the length of balance is not fix. eg. $100 -> $90, vice versa.

    You cannot update a file that way. You're going to have to read the file and rewrite it in another file replacing the old balance value with the new balance value and then overwrite the old file with the new file.
    If the file is not to big you can load the whole file in memory with a String then work on that before rewriting it to the file.
    Otherwise your going to have to read chunks of lines and append them to a temporary file.
    I suppose this is no enteprise application but only a student's assignment, or else you should of course use a database for that kind of job!

  • How to update a text file or change some text easily ??

    Hi
    I want to change some text inside a text file. I can do it as below:
    1) new a File file
    2) new a FileInputStream(file) and call read()
    3) modify text
    4) new a File newfile
    5) new FileOutputStream(newfile) and call write()
    6) delete file
    7) rename newfile to file
    It is too complecated. What is easy way to do it ? Thanks for help
    Gary

    Hi NLSurfMan,
    I ceate a coding below , it always give me error:
    java.io.FileNotFoundException: c:\abc\file.rtf (The process cannot access the file because it is being used by another process)
    I have closed the FileReader and BufferedReader. I still have this problem. Why. Thanks. Gary
    int c;
    String text="";
    File filename=new File("c:/abc/file.rtf");
    FileReader fileReader =new FileReader(filename);
    BufferedReader bReader=new BufferedReader(fileReader);
    while ( (c=bReader.read())!=-1 ) {
    text=text+(char)c;
    bReader.close();
    fileReader.close();
    System.out.println("text="+text);
    text=text+" I want to make some change here";
    File filename1=new File("c:/abc/file.rtf");
    BufferedWriter bWriter =new BufferedWriter(new FileWriter(filename1));
    bWriter.write(text,0,text.length());
    bWriter.close();

  • Keeping edits when updating linked text file

    My main use of indesign is laying out text files that are created in work. They need be linked, becuase the authors of these files are constantly updating them.
    I place the file, and then format the tables to make them look better, and also sometimes add images into the text
    However, when the original changes, and I update the text box with the new text, all the formatting i've added is lost.
    This must be a common problem with linked files, so, if anyone has any recommendations please let me know. Most importantly would be a way to automatically apply / keep the stlying for the tables.

    You can try exporting to RTF and relinking those files back to your
    document and letting your writers work on those, but InCopy is far
    better solution.
    Why not download the demo and show them how much time they'll save with
    it? Or bring in a consultant who can demonstrate it. I've found that
    doing a demo can really open some eyes to the possibilities.
    Bob

  • Want to update a text file and reflect the same on iview immediately

    Dear friends,
    I have a text file in a repository path
    I could read each line and do some task.
    My query is for each line task, i would like to update a file (for me it is log file) and reflec the same on a iview in the same page
    sample code appreciated
    regards
    Kantha

    If the user backs up their device to either iCloud or Mac/PC, they can restore the app data from that backup.
    There's no need to do what you intend.

  • Interactive Bar/pie chart and line graph, data from excel/text file -urgent

    Hi,
    I have a huge data in excell sheet which keeps updating every month. Data basically consists of service provider and there respective subscribers from various regions of the country over the years. The requirement is to give the viewers an interactive page where in they can make various combinations and can compare, cross examine data according to thier choice.
    We want the pie chart / bar graph or line graph to be created on the fly according to the combination made by the user.
    The site is hosted on a red hat linux server. how can a connection to the excel spreadsheet be made or is it possible to read from the text file if the entire data is exported to a text file.
    Is there any ready made tool/code available which can be customised according to the need.
    Thanx in advance
    Regards
    Prakash

    I certainly wouldn't pay for the graphing package at the previous link. check out http://www.object-refinery.com/jfreechart/ for a free, open-source, much better looking graphing package.

  • Table update from text file on server

    How do I get a table in dreamweaver to update from a text
    file thats on the server it will be posted on? Do I need to use
    some sort of weird coldfusion or asp.net, or can i do it in basic
    html. It would be sweet to make happen for my portfolio news
    section ... thanks!

    Hello,
    What you need is to know the structure (fields) of your internal table LS_BKPF at runtime.
    The standard SAP class CL_ABAP_TYPEDESCR contains Methods to describe not only repository structures but also variables used in your ABAP program.
    DESCRIBE_BY_DATA : Description of data object type
    DESCRIBE_BY_NAME : Description of object type using relative/absolute names
    DESCRIBE_BY_OBJECT_REF : Description of object type using reference
    DESCRIBE_BY_DATA_REF : Description of data object type using reference
    Example on how to do this can be found here :
    [http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3414700)ID1687263150DB21033411053326729243End?blog=/pub/wlg/2071|http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3414700)ID1687263150DB21033411053326729243End?blog=/pub/wlg/2071]
    After you have retrieved the fieldnames of your internal table at runtime you can add them in the first line of your dataset.
    Success.
    Wim

  • Hash Table copy to Text file : urgent

    HI
    I have a hash Table which cintaine id's and name pair Now i want to copy or dump this whole table into a Text file, But i do not know how to do this .
    This is very urgent for me.
    Please help me .
    Preeti

    HashTable is Serializable
    use ObjectOutputStream to write to the file and use ObjectInputStream to read from the file
    HashTable ht=new HashTable()
    ht.put("key1","value1");
    ht.put("key2","value2");
    FileOutputStream ostream = new FileOutputStream
    ("Hash.txt");
    ObjectOutputStream oos = new ObjectOutputStream(ostream);
    oos.writeObject(ht);
    oos.flush();
    oos.close();//dont forget thisuse ObjectInputStream To read HashTable from file
    use readObject() method

  • MORE HELP ON TEXT FILES - URGENT

    I'm Writing a Business Professionals Of America Database for the High School I attend and I need to know about some input and output to text files
    Suppose I have a String called 'line1'
    I also have a textfile called 'C:/......../info.txt'
    In that text file I have the line '34865-M-J-101'
    Can someone show me how to take that line out of the text file and place it into 'line1'???
    The second thing I need to know is.............
    I have a TextField in my java program, once the user enters something into the textfield and clicks a button I made, I need to take that information and output it to a text file. I know how to take the information OUT of the textfield and into a variable, I just need the code on how to output the variable's information to a textfile.

    I'm Writing a Business Professionals Of America
    Database for the High School I attend and I need to
    know about some input and output to text filesHow much information do you have. If there is a lot of information I would recommend using an actual database instead of a text file.
    Suppose I have a String called 'line1'
    I also have a textfile called 'C:/......../info.txt'
    In that text file I have the line '34865-M-J-101'
    Can someone show me how to take that line out of the
    text file and place it into 'line1'???That looks like some kind of ID. What you could do (also I'm assuming you don't have a tremendous amount of data, otherwise use an actual database) is use the java.util.Properties class and setup your data as lines with "34865-M-J-101=some entry for that". Then you could use code like:
    Properties props=new Properties();
    props.load(new FileInputStream("C:/....../info.txt"));
    String line=props.getProperty("34865-M-J-101");The line would then have "some entry for that".
    The second thing I need to know is.............
    I have a TextField in my java program, once the user
    enters something into the textfield and clicks a
    button I made, I need to take that information and
    output it to a text file. I know how to take the
    information OUT of the textfield and into a variable,
    I just need the code on how to output the variable's
    information to a textfile.Assuming you took the approach above something like:
    props.store(new FileOutputStream("C:/....../info.txt", null));The best way to do this really depends on how much information there is and what you need to do with it. For example, if you do not have some unique key for each entry, you probably don't want to use properties.

  • Latest Adobe Reader update deleted all files from my desktop - help please!

    Dear all!
    Yesterday I opened up a .pdf document with Adobe Reader. I clicked the Help | Check for Updates option. The reader informed me that there was an update available. I then disabled my antivirus (as is recommended). I selected the available update by checking the box next to it. I then clicked the Download option.
    The update began to download. At that moment I noticed that the .pdf document was still open (i.e. Adobe Reader was still running). Knowing that the installation, when it begins, tends to notify me that it must close Adobe Reader in order for the installation to continue, I decided to close Adobe Reader myself before being prompted to do so. All was fine until that moment, as the update download and install runs in a completely separate process from the Reader, it was not affected.
    After I closed the Reader, with the update still running I noticed that all files I had on my desktop were gone. None of the folders were missing, just the single files and most of my shortcuts. I checked to see if the files were just invisible or phisically missing. It was the latter. Windows Explorer showed that all files I had on my desktop were gone (deleted/overwritten I guess). A search of my computer for the file names came up empty, even though I was searching with the "search hidden and system files" options enabled!
    I tried a number of deleted file restoration softwares but none have identified the desktop files I was missing.
    Be so kind as to spare me from the "did you check the power cord" category of "answers", as I am not a complete idiot. The Acrobat Update, or something associated with it has to be at the root of this problem, as the antivirus software I have installed came up empty when I searched the computer for virurses, worms and the likes...
    All help on this matter would be appreciated. Needless to say, most of my current work was stored on the desktop...
    I am running WindowsXP sp. 3, Acrobat Reader 9.34
    With regards
    jack_84

    Please ignore the previous unrelated reply - I will deal with it separately.
    I must first say that this is a very puzzling problem, and that I have never heard of anything like it.  Apart from the missing desktop content, it also puzzles me that you state your Adobe Reader version as 9.34, when the latest Reader version is actually 9.3.2.
    Anyway, how to solve it?  Can I assume that you do not have a very recent backup, from where you can simply restore all the lost content?
    I do not know if your desktop content is really gone (deleted), or if it is somehow just not visible.  There are a few things we can try, but I strongly suggest that you make a full backup of your system before you try anything!
    Since I have never seen this before, I cannot make any definitive recommendations, but just suggest what I would do if that happened on my computer.  Again, not before making a full backup.
    Uninstall Adobe Reader.
    System Restore to a time before the problem started.
    Check the following registry keys, if they have a value 'NoDesktop', and what it is set to
    HKCU\Software\Microsoft\Windows\CurrentVersion\policies\Explorer
    HKLM\Software\Microsoft\Windows\CurrentVersion\policies\Explorer
    If you are on XP Pro, you can use gpedit.msc to check these settings (Configuration | Administrative Templates | Desktop ["Hide and disable all items on the desktop"]).
    Message was edited by: ʇɐb ɹəuəllıʍ - typos.

  • Update a text file (using eScript)

    Dear All,
    I have a parameter file which is a text document (word, notepad, textpad, ...). THIS DOCUMENT IS LOCATED IN A FOLDER OF THE SIEBEL SERVER.
    I would like to give to my users the ability to update it when a button present in the SIEBEL application is clicked.
    I have proposed to use the ComCreateObject command but it seems that this command runs in local mode. The editor (Word, NotePad, TextPad, ...) must be installed on the client. And this is not always the case. Also, I have security constraints on the folders of the Siebel server.
    How can I update (by using my local SIEBEL application) a text document located in the SIEBEL server.
    Any idea would be greatly appreciate.
    Thanks a lot.

    It looks like you are opening a can of worms here.
    It is possible to execute Notepad or Wordpad on the client side, by instantiating the ActiveX through Browser Script.
    You can search on "ActiveXObject" on Supportweb for more info.
    But this probably won't solve the security on the server directories.
    You could try to give every user an exclusive sub-directory, but this will cause a lot of administration.

  • Windows 7 Automatic Update deleted my files!

    I am running Windows 7 Home Premium 64-bit.
    Last night two updates were automatically installed when I shutdown my computer: KB976098 and KB915597
    This morning when I turned on my computer, all my files appear to have been deleted, and although installed software is still there, programs (e.g. iTunes, Google Desktop) have lost all settings and act as though it were a new installed.
    - over 200+ photos in My Pictures GONE
    - entire iTunes music library GONE
    - Desktop shortcuts GONE
    - Programs pinned to taskbar GONE (reverted to original default so programs I had removed reappeared)
    Oddly enough, everything in my Recycle Bin was preserved.  The Windows.old folder was also preserved.
    Needless to say, after my painstaking effort to upgrade to Windows 7 from XP, this is more than a minor annoyance.  Everything is backed up (I think) so I should be able to restore what has been lost but WTF MICROSOFT?!  If automatic updates are going to wipe out My Documents, a little warning.
    Has anyone else had a similar problem?

    Ok guys I think I may have figured this out although I'm not so vain as to think it will work for everyone. I'm hoping it does though and I would appreciate you letting me know if it does. Here goes:
    Last night 5/25/2011, while surfing and studying I ran across a website about accounting. I'm not sure what happened but something definitely did cos my computer started acting weird and then I got an error. It was a User Account Window asking me to allow
    some program and click yes or no. I clicked no like 12 times and it just kept coming back. Since it was a common "Windows" window that I'd seen b4 I finally clicked yes just to get rid of it that's when it happened. 5 seconds later I got an error about my
    hard drive and that I needed to restart. It would not go away and then I saw the screenshots on this page. This was the virus only I didn't know it at the time.
    http://www.microsoft.com/security/portal/Threat/Encyclopedia/Entry.aspx?name=Trojan%3aWin32%2fFakeSysdef&threatid=2147639286
    Anyway, I closed my lid last night with the error window still open and went to sleep. When I "resumed" this morning all my data was gone. This includes programs, files, pics, music everything. I almost cried. I call this my million dollar laptop: Toshiba
    A665. Anyway, I immediately restored to 2 days ago and all I got back was my programs but no files. I started searching and found a deleted file. I suspected they were there on HD somewhere. I followed the path to the folder and no file. I remember hiding
    files from my ex a while ago so I went to the Start Menu----->My User Account---->Organize---->folder and serach options--->View ----in the list below select Show all hidden files and folders and apply it. All my files suddenly appeared. They were
    all hidden by the virus and they still are. Even though i can see them, they are transparent and the properties are changed on each one.  I had to right click each one, go inside properties and change the Attribute from Hidden and Apply. That's it
    and I am so relieved. My antivirus found the FakeSysdef file and removed it. So far so good. Let me know if this works for you!

  • Is it possible to read/write to text file without deleting it?

    I know how to read from a text file and how to write to a text file. The problem that i have is i need to use a text file to store data for my application to read and also for my application to write. I would like it if i could write two programs really, one reads, the other is used to update the text file. This file is a list of verbs. I thought about using databases but i couldn't get them to work. I downloaded MySQL server 5.0 and installed it. I then downloaded the driver from http://www.mysql.com/products/driver and ran the auto installer. it said everything worked out perfectly but when i try these lines:
    Class.forName("com.mysql.jdbc.Driver");
    I get a SQLException that says no suitible driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    ( I thought this driver came with the JDK but i guess not, i just read about it in a java book)
    I get a ClassNotFoundException
    that just says sun.jdbc.odbc.JdbcOdbcDriver
    So yeah, SQL is pretty much not working. I need a solution to my problem, either by using text files, or a different type of database. I heard you could use excel to create a database but i have no idea how and i hear microsoft access could also do this, however i don't have microsoft access and i don't intend on paying for it. So, here are my questions:
    1st, is there a tutorial on using excel databases in java programs
    (if not)
    2nd is there a way to read/write/update a text file without deleting it?
    (if not)
    3rd is there a way to get SQL working, i have windows vista this could be the problem
    (if not)
    4th what could i do to store information on the hd for reading and modifying later?
    thanks, lateralus

    A database might be overkill just for a list of words.
    Thoughts:
    <ul>
    <li>What is the extent of your "file updating"? If you are just appending to the file, opening it in append mode will keep the file from being clobbered.</li>
    <li>Otherwise, why not create new files instead of editting them? The file names could include a version number or timestamp, allowing the reader to select the newest one.
    </li>
    </ul>

Maybe you are looking for