Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Regarding File Handling

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Thanked 0 Times in 0 Posts

    Default Regarding File Handling

    I made a project in which i am using 2 files

    1st file contains the path of the programs
    2nd file contains the associated image icon's path

    Now when i want to delete a button (which is using both data from the above files)
    At that time it is easy to delete the program path from 1st file

    But it is difficult for me to delete the icon's path from 2nd file as 2nd file may contain same image icon like others so how can overcome such a problem

    1st File


    2nd File


    Now i want to delete the button that is present in ../b.exe
    I can delete it from 1st File
    but how should i delete from 2nd file?
    Can you provide me a snippet so that it will be easy for me to understand
    Thanks in advance

  2. #2
    Junior Member
    Join Date
    Mar 2010
    Thanked 0 Times in 0 Posts

    Default Re: Regarding File Handling

    I'm guessing your algorithm works on the assumption that each line in file1 corresponds to that same line in file 2 ..? (In other words, line 1 in file 1 should be the same item (aka: program&icon) as line 1 in file 2....)

    In which case, you could simply perform a string check against each line of file 2 to make sure that they end with the "[filename]" (minus the ".exe" and replace with ".png"), and only remove that line (or rather, exclude it from being re-written) if it matches the item you want to delete.

    So for example...
    String itemYouWishToDelete = "item.exe"; //     <-- What ever you've clicked on...
    File file2 = new File("file2.txt");
    Scanner scanner = new Scanner(file2);
    while (scanner.hasNextLine()){
            String line = scanner.nextLine();
            if (line.endsWith(itemYouWishToDelete.replace(".exe",".png"))) {
                // delete the item

Similar Threads

  1. File handling in java
    By srikanth in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: February 22nd, 2010, 02:11 AM
  2. Replies: 8
    Last Post: January 6th, 2010, 09:59 AM
  3. Event handling
    By subhvi in forum AWT / Java Swing
    Replies: 3
    Last Post: August 26th, 2009, 11:20 AM
  4. Exception handling for TextFields
    By FretDancer69 in forum AWT / Java Swing
    Replies: 1
    Last Post: June 16th, 2009, 07:48 AM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 09:37 AM