How can i delete a UserName  from a text file using Strings or io.

hi i m trainee
i have been assigned to make java program which deletes a UserName and
his Passwor from a Text File
i m unable to do it using the code below
plz help
do reply
  import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java .applet.*;
import java.io.*;
class Del extends JFrame  implements ActionListener
     String s2;
     JTextField CWDMUserDText = new JTextField();
     JButton CWDMSecDelButton = new JButton("DELETE");
     JLabel CWDMUserLabel = new JLabel("USER NAME");
     JPasswordField CWDMPassDText = new JPasswordField();
     JLabel CWDMPassLabel = new JLabel("PASSWORD");
     //String user,pass;
     /* CONSTRUCTOR*/
          Del()
               Container contentPane=getContentPane();
               contentPane.setLayout(null);
              setLocation(400,200);
               contentPane.add(CWDMUserDText);
               contentPane.add(CWDMSecDelButton);
               contentPane.add(CWDMUserLabel);
               contentPane.add(CWDMPassDText);
               contentPane.add(CWDMPassLabel);
              CWDMUserLabel.setBounds(20,70,100,25);
              CWDMPassLabel.setBounds(20,100,100,25);
               CWDMUserDText.setBounds(150,70,100,25);
               CWDMPassDText.setBounds(150,100,100,25);
               CWDMSecDelButton.setBounds(80,135,100,25);
               CWDMUserDText.addActionListener(this);
               CWDMPassDText.addActionListener(this);
               CWDMSecDelButton.addActionListener(this);
               contentPane.setBackground(Color.CYAN);
               setVisible(true);
               setDefaultCloseOperation(EXIT_ON_CLOSE);
     public void actionPerformed(ActionEvent ae)
              if(ae.getSource()==CWDMSecDelButton)
     //             user = CWDMUserDText.getText();
     //          pass = CWDMPassDText.getText();
     //          showarr();
               s2 = CWDMUserDText.getText();
               CWDMUserDText.setText("");
               CWDMPassDText.setText("");
               DelUser(s2);
          public static void main(String args[])
               Del myframe1= new Del();
               myframe1.setSize(300,200);
               myframe1.setVisible(true);
          public void DelUser(String s)
               //int a;
               try
                    FileReader fr = new FileReader("file.txt");
                    BufferedReader br = new BufferedReader(fr);
                   String s1;
                   int a;
                   int len = s.length();
                   System.out.println(len);
                   //s2 = CWDMUserDText.getText();
                    while ((s1=br.readLine()) !=null)
                         if((a=s1.indexOf(s))>0 && (a=s1.indexOf(s))!=0)
                              System.out.println(a);
                    fr.close();
               catch(FileNotFoundException e)
                    System.out.println("exception occured");
               catch(IOException e)
                    System.out.println("io");
     }

Some tips:
1) If you are adding or deleting stuff from a text file you need to write a new, modified file and then, optionally, do something like:
rename the old file to whatever.bak or the like.
rename the new file to the old.
2) Don't depend on System.out so much on a GUI application. For example if you get an exception use javax.swing.JOptionPane to display an alert (and show the message from the exception). You can write the stack trace to System.out if you want.
3) Don't muck about with calculating bounds for screen objects, let a layout manager sort it out. I like BoxLayoutManager for most things like this.
4) For bonus points do your IO in a separate Thread. Generally you don't want anything happening in an actionPerformed method which significantly delays it's return. The method should launch a new Thread to do the job, and disable the button until the Thread finishes.

Similar Messages

  • How can you delete iOS 8 from iPad, it is using too much memory

    how can i delete ios8 from my iPad? since i downloaded it my iPad is slow, pages sometimes get caught in endless loop, and is taking up all of my storage

    If you haven't installed it yet, settings, general, usage, populate the whole list and you should be able to remove the installer. (last I read you could delete it, with iOS7 the installer was not able to be deleted)
    If you've already installed it, Apple does not support downgrading. If you'd like to go into specific issues, maybe people here can suggest some fixes or work arounds.

  • How can I delete an app from launchpad, that doesn't have the little cross in the left top corner. The app isn't an App Store app. The application is also not present anymore in my application's folder in finder.

    How can I delete an app from launchpad, that doesn't have the little cross in the left top corner. The app isn't an App Store app. The application is also not present anymore in my application's folder in finder.
    I tried to use the attached command through TERMINAL :
    sqlite3 ~/Library/Application\ Support/Dock/*.db "DELETE from apps WHERE title='Help';" && killall Dock
    sqlite3: Error: too many options: "DELETE from apps WHERE title='Help';"
    Use -help for a list of options.
    But i didn't work as I got the above error message.
    best regards
    Jeroen

    I'm in the same boat as you -- except that I manage both a school lab (volunteer job) and macs in the enterprise (pay job).  What I think we need is the Education Volume Purchasing Program
    http://www.apple.com/education/volume-purchase-program/faq.html
    Unfortunately this all seems a little rough around the edges -- for example, I have found updates for AppStore apps on the support.apple.com updates download site, but then when I install them via ARD they don't actually update the software.  (The AppStore icons still show as needing the updates, and the version info reports the old version.)  The documentation is also vague about which AppleID to use in which circumstance.  I think they just haven't finished thinking through the implications of the various procedures and policies upon the various kinds of customers.  When we deployed Mountain Lion on the school lab, we made an install usb and went around and installed it on each computer -- and it appears that you are on the honor system as far as paying for all of the licenses that you install.  We did!  But they appear to have no way to enforce it.
    So far, I have only deployed 9 Lion macs in my day job, and our "solution" to the AppStore showing updates problem has been to drag the AppStore icon off of the users' docks so they don't see them!

  • How can I delete some music from my iCloud but not from my iTunes in my computer? please??

    how can I delete some music from my iCloud but not from my iTunes in my computer? please??

    iCloud doesn't store your music.

  • How can i delete some books from ibook?

    How can i delete some books from ibook? It says: this book can't be opened. The book is corrupt. I can't open and I can't delete it

    I was unable to delete a book sample from my iPhone 5s running iOS 7.  This seems to be what worked for me.  I went to the Library and clicked "edit" in upper right side of the screen.  I then tapped one time on the book I wanted to remove and a blue check appeared at the bottom right corner of that book (presumably you could tap several at a time)  Anyway, when the blue check is on the book, you will see in the upper left of the screen the word "Delete" (mine was in red) I clicked that and then a confirming dialog came up from the bottom of the screen with the choices of "delete" or "cancel".  I chose "delete" and the book was gone.  Hope this helps.

  • How can i Delete all foto from my iphone and after some time get them one more time on it but not as a new album :)?

    How can i Delete all foto from my iphone and after some time get them one more time on it but not as a new album, i want them in the camera roll ?

    How can I delete EVERY THING off my Mac and have it like new?
    Boot from the software install DVD and do an "erase and install" when prompted.

  • How can I delete a video from an album on my iPhone 5?

    How can I delete a video from my iPhone 5? I created an album and accidentally placed a video in the album and want to delete it. Is it possible to delete a video or picture from an album?
    Thanks!

    How do I delete photos from my Photo Stream in iCloud?
    Individual photos cannot be deleted from your Photo Stream. You can, however, delete all the photos in your Photo Stream by clicking the Reset Photo Stream button in your account at icloud.com. The Reset Photo Stream button will instantly delete all Photo Stream photos stored in iCloud, but it will not remove any Photo Stream photos that have already been pushed to your devices."
    iCloud: Photo Stream FAQ

  • How can I delete an Invitation from March that shows as new/unanswered in my calendar and there is no ability to scroll to address availability?  iPad 3 5.1.1

    how can I delete an Invitation from March 2012 that shows as new/unanswered in my calendar and there is no ability to scroll to address availability?  iPad 3 5.1.1

    Thanks!
    Another question:  If @me.com and @icloud.com are interchangeable, is it possible to delete the @me.com address? (would like to de-clutter and avoid confusion in the future)

  • How can I delete Apple ID from my old phone that it is not with me?

    How can I delete Apple ID from my old phone?

    You cannot delete Apple ID. You can change the password so the Apple ID without the correct password will be useless for others.
    If you still have the old iPhone:
    Wipe iPhone/iPad/iPod touch clean
    There are a few steps to do:
    Switch off iMessage in Settings > Messages
    Switch off FaceTime in Settings > FaceTime (iPod touch 4th Generation or later, iPhone 4 or later and iPad 2 or later)
    Delete iCloud in Settings > iCloud > Delete Account
    Finally Settings > General > Reset > Erase All Content and Settings.
    If device is registered: Un-register your device: https://supportprofile.apple.com
    Now you can sell/give.
    Message was edited by: ckuan

  • How can I delete a song from iCloud / iTunes Match, but keep it on my Mac?

    How can I delete a song from iCloud / iTunes Match, but keep it on my Mac?
    I subscribed to iTunes Match a few weeks ago and my entire library was uploaded.  I do not want all of my library in the Cloud, especially given that there is a space/song limitation.  Any help is appreciated.
    Thanks!

    Apologies Brandon, we have moved on somewhat from your original question.
    What I have done is effectively used Michael's idea. I'll try to explain a little further.
    You can run iTunes match on up to 5 computers, and you can edit the iCloud library on any of them. Michael's idea works on the basis that, whilst you can edit the iTunes library, you can't remove songs from other computers.
    I have basically the same setup as you, but I also have a MacBook Air, which is running iTunes Match but without any music downloaded so it all streams.
    I added the songs on my main library, which then added them to the cloud. When they appeared on my MacBook I deleted them straight away. As there was no local copy I was asked if I wanted to delete them from the cloud, and I said yes. When I went back to my main computer I found that, as expected, they were still there, but the iCloud status is "removed". They are therefore on my library but not in iCloud.
    Since then I have run match updates a couple of times and there is no sign as yet that it will try to add them back to the cloud. It's too early to say that this is a definate answer to your problem, but it looks very hopeful.
    Our other discussions have moved onto the 25,000 son limit, which I note from your comment you may also be interested in. Watch this space.
    If you don't have access to a second computer to run the other library on then look back at Michael's post where he explains how to set it up on your main computer.
    Hope that clarifies a bit.

  • How can I delete an app from the cloud??

    how can I delete an app from the cloud, so nobody can download it again to my phone?? please I tried from the computer but it just hide the app from purchased, and still appears in the app store with the cloud on it

    At the present time, you can't hide or delete an app from your purchased list on your phone.  Prior to iOS 6 you could hide it; there has never been an option to delete it.

  • How can i delete purchased items from the cloud in iTunes

    how can i delete purchased items from the cloud in iTunes

    I had this problem as well. You can't delete them but you can hide them by swiping across from the cloud to. The other side then pressing hide

  • How can I delete an app from my account definetly?

    How can I delete an app from my account, not just from the iPad,  i want to delete some from "purchased apps", hopee you can help me

    Rudegar is correct - you cannot remove the app permanently from your account. There has been much discussion about this on the ASC site and many users have concerns for many different reasons. As suggested send feedback to Apple.
    But remember this - your account is a part of Apple's official and legal sales records. In the real world - you just cannot delete a record of sale - for accounting reasons and for legal reasons.

  • How can I delete a movie from my iphone?

    How can I delete a movie from my iphone?

    Under iOS 7, in the Videos app with Movies selected sekect the Edit button at the top right. An X will be available on the movie to select to delete.

  • How can I delete an attachment from a received email but save the message?

    Hi all, how can I delete an attachment from a received email but save the message?*

    Over the years this issue crops up again and again. Here are the cases I know about:
    Case 1 - it simply doesn't work
    I have a message in my inbox with a jpeg of about 300Mb. Select message, choose option "remove attachment" which is not greyed out, and it does not work.
    Case 2 - it works if you save the message first
    I move the message from the inbox to a mail box. Open the mailbox (select), select the message, choose option "remove attachment", result: the attachment is removed, a small text file is added and an error appears in the message "missing plug-in". The message size is reduced from 300Mb to a few bytes.
    Case 3 - the option "remove attachment" is greyed out.
    I've googled this at least 10 times and read all the advice about editing various files from the library and all the other hacks. The simple truth here is that the user should not be inconvenienced by such inappropriate behaviour. We're not used to this from Apple any more, not since OS X. Even Windows does this stuff painlessly. In fact this kind of function is something that Outlook and Exchange do incredibly well. If they didn't the corporate world would have ground to a halt.
    My point: the remove attachment option should work all the time and should be redesigned. Right-click + save as + delete in the message would be a hundred times easier.

Maybe you are looking for

  • Satellite C50-A-15L: unable to play music or video files via media player

    Hi all I am having problems with my media player and explorer functions all of a sudden - it seems to have occured after a recent 'important update' (always causes more issues than fixes). Anyway, since this update, I have been unable to play any mus

  • Windows Frustration

    Greetings. About a year ago we did an interactive sales piece in flash that loads and unloads different FLV files contained within SWFs for each section. It was recently brought to our attention that you can only watch each video one time on Windows

  • Update from 3.04 to 3.06 by Ovi Suite on n X6-00

    When I open Ovi Suite, connect my X6 and go to Maps, I can check which maps are available and which maps are installed. However, there seems to be no method to check the version numbers. Thus, I risk to reinstall all my 3.04 maps(which I think are in

  • Android: Consistent Segmentation Fault Crashes

    Hello, On the Nexus 7 (running Android 4.3), the DPS app consistently crashes within 5-20 seconds of running the application. I looked at the logs with the Android Device Manager and this is what I found. I have included everything that occurred betw

  • Drive App on N9

    The N9 Navigation is very limited. I did find the following limitations; 1. There is no Favourite Tab/option 2. There is no Save location option. 3. There is no Fastest/Smallest Route option. 4. Once you select a destination, the Navigation Mode keep