Save the contents into hard disk on click of Save As button in Swing

Hi,
I have a JButton "Save As". On clicking the button, the contents in the JTextArea should be saved in the local hard disk by opening a Save As dialog box and allowing the user to save in any location.
Is it possible to do this? If so, please inform me how it could be done.

Hi,
Please find the code below.
try{
File f = new File("Out.txt");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); String stb = null;
JDialog w = null;
stb = new String();
stb = dis.readLine();
if(stb != null){
w = new JDialog();
final Container c = w.getContentPane();
c.setLayout(null);
w.setContentPane(c);
w.setResizable(true);
w.setTitle("Log Window");
w.setSize(330,500);
final JTextArea jt = new JTextArea();
JScrollPane jsp = new JScrollPane(jt);
jt.setLineWrap(true);
jt.setText("Records not available for the id's"+"\n"+stb);
jt.setBounds(10,10,285,500);
final JButton jbSave = new JButton("Save File As");
JPanel spacer = new JPanel();
spacer.setMinimumSize(new Dimension(50, 18));
spacer.setPreferredSize(new Dimension(50, 18));
JPanel jpButtons = new JPanel();
jpButtons.add(jbSave);
jpButtons.add(spacer);
jpButtons.setBorder(BorderFactory.createEtchedBorder());
JScrollPane scroll = new JScrollPane();
c.setLayout(new BorderLayout());
c.add(jt,BorderLayout.CENTER);
c.add(jpButtons, BorderLayout.SOUTH);
jbSave.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
JFileChooser fileChooser = new JFileChooser();
int userOption = fileChooser.showSaveDialog(null);
if(userOption == JFileChooser.APPROVE_OPTION)
//*******************STATEMENTS TO BE ADDD****************** }
jt.getText()-----This is how I can get the contents from JTextArea.
But how I can save the contents. i.e on click of Save As button, Save dialog box opens, and I can choose the location and give the name. but if I go to the location I don't find the file....
Please guide me to finish this....
Thanks in Advance.....

Similar Messages

  • Is it possible to save the content of a form before click on the submit?

    Hi,
    I'd like to know if it's possible to save the content of a text field in a form in a String variable run-time before click on the submit botton?
    If this is not clear what i want to say,please tell me, and i'll try to say it better.
    Thanks a lot.

    I've got a form with a text field and everytime i add
    a letter in this text field i want to use this string
    as parameter to execute a query.So,in the end, the
    number of query that I'll execute is equal to the
    length of the string i've insert to the text form.If you mean executing a database query, JavaScript would not be able to do that. JSTL sql tags might help.

  • How to read a file and save the contents into array list

    i have textfile contains information like:
    Name: James Smith
    Customer no: 663,282
    Post code: BA1 74E
    Telephone no: 028-372632
    Last modified: Feb 10, 2008 6:50:00 PM GMT
    Name: Janet Smith
    Customer no: 663,283
    Post code: BA1 74E
    Telephone no: 028-372632
    Last modified: Jan 11, 2007 8:10:05 PM GMT
    etc...
    how can i read the contents of this textfile and put the data into an ArrayList called ArrayList<Customer> customerList.
    i knew that i need two classes, one for CustomerDetails and one for ReadFile.
    i have already done the customer class as:
    import java.util.Date;
    public class Customer
        String Name;
        int CustomerNo;
        String Postcode;
        String teleNo;
        Date lastModified;
        public Customer(String Name, int CustomerNo, String Postcode, String teleNo, Date lastModified)
         assign(Name, CustomerNo, Postcode, teleNo, lastModified);
        public void assign(String Name, int CustomerNo, String Postcode, String teleNo, Date lastModified)
         this.Name=Name;
         this.CustomerNo=CustomerNo;
         this.Postcode=Postcode;
         this.teleNo=teleNo;
         this.lastModified=lastModified;
        public String toString()
         String allDetails = "Name: "+Name+
             ", Customer No: "+CustomerNo+
             ", Postcode:"+Postcode+
             ", Telephone No: "+teleNo+
             ", Last Modified Date: "+lastModified;
         return allDetails;
    }i just wondering how can i code the ReadFile class?
    can anyone help me please. thank you in advance.

    thank you for your suggestion, but i have already started to code the readCustomer class using the Scanner.
    the code i got so far is:
    import java.util.Scanner;
    import java.io.*;
    public class readCustomer
        public static void main(String[] args)
         readCustomer("Customers.txt");
        public static void readCustomer(String filename)
         try {
             Scanner scanner = new Scanner(new File(filename));
             scanner.useDelimiter(System.getProperty("line.separator"));
             while (scanner.hasNext()) {
              processLine(scanner.next());
             scanner.close();
         } catch (FileNotFoundException e) {
             e.printStackTrace();
        public static void processLine(String line)
         Scanner scanner2 = new Scanner(line);
         scanner2.useDelimiter("\\s*:\\s*");
         String description = scanner2.next();
    *// here is where i am struggling. i don't know how to get the information after the : sign*   
    }i am currently struggling with the processLine method?
    also, i am not sure how to group a set of information and put them into the arraylist.
    Any hint, please. Thank you.
    Edited by: mujingyue on Feb 26, 2008 12:42 PM

  • How to save the contents of one file into another file?

    Hai,
    i'm trying to save the contents of an existing file into a new file...
    for example.. if i'm having a ms word file namely ss.doc..
    now i want to save itz contents into another file namele dd.doc..
    How shall i do it..
    Can an one plzz explain me...
    senthil.

    Hi, Senthil.
    This Forum is not a general discussion forum.
    You don't believe that the InDesign SDK is a general purpose API. Do you?
    I think you must post issues like this where they belong, in this case in a Microsoft Word Forum.
    Best regards.
    Oscar.

  • How to save the content of a JTextArea into a txt file?

    Hi, I want to save the content of a JTextArea into a txt file line by line. Here is part of my code(catch IOException part is omitted):
    String s = textArea.getText();
    File file = new File("file.txt");
    BufferedWriter bw = new BufferedWriter(new FileWriter(file));
    bw.write(s);
    bw.close();
    But I found in the file all is binary code instead of text, any people can help me?
    Thanks in advance

    I can see text in the file now, but the problem is
    when I write three lines in textarea, for example
    111
    222
    333
    then I open the txt file with notepad, it is
    111222333
    How to save them line by line? Use a PrintWriter. It lets you write lines (it's the same class as System.out).
    http://java.sun.com/j2se/1.4/docs/api/java/io/PrintWriter.html

  • Using I-Sight to save videos to your Hard Disk

    Hi everyone!
    I've got a Problem with my integrated I-Sight Cam:
    IMovie doesn't recognize the camera if i want to capture a video... i've looked for a solution to this problem but i only found the information that it works with Quick Time Pro - but i don't wanna buy that. Has anyone a idea how it could work to capture videos and save them to your hard disk?
    thanks, Nargilek
    IMAC Core Duo 17"   Mac OS X (10.4.5)  

    Try this . . . open iMovie and click on "Create New Project", then Select video format "iSight" and click on "Create". After the next window appears click on the small camera image in the title bar below the iSight movie image, then inside the iSight image click on "Record with iSight". Complete your movie and click again on "Recored With iSight to stop recording. Don't forget to save the movie.
    Good luck.

  • Stop the beeps with the 7200 rpm hard disks of the MacBook Pro

    http://www.hardmac.com/news/2009/07/13/stop-the-beeps-with-the-7200-rpm-hard-dis ks-of-the-macbook-pro
    Stop the beeps with the 7200 rpm hard disks of the MacBook Pro
    from HardMac.com by [email protected] (Lionel)
    At the beginning of week, we have spoken about the unpleasant beeps made by the 7200 rpm hard drive proposed as an option in the MacBook Pro 2009.
    A solution has been found, the details are given by Rémy.
    These tedious beeps occur when the disc is inactive and are caused by a system
    to reposition the play-back head carried out in a repetitive way.
    In addition to the beeps of the hard drive, Mac OS X displays the pretty multicoloured wheel during some seconds while waiting for hard drive to finish these loadings and unloadings of the play-back head.
    The solution comes with a utility of the name hdapm (for Hard Disk Advanced Power Management) which makes it possible to change the level of energy management (APM) of the hard drive.
    Hdapm can be downloaded from : http://mckinlay.net.nz/hdapm; hdapm being a command line utility, it is thus necessary to use the Terminal (which is in /Applications/Utilitaires).
    After copying hdapm into your user file, the command to enter is:
    sudo ~/hdapm disk0 max
    disk0 corresponds to the disc to regulate knowing that hdapm should function with any ATA disk supporting APM
    max is the level of APM which is a number ranging between 1 and 254 included
    the word following are preset and can used in the place a number for the level of APM
    max (maximum performance) is the parameter to use to eliminate the “beeps”.
    min (maximum economy of energy)
    default (returns to the default setting)
    The level of APM is a temporary adjustment in the firmware of the hard drive, this adjustment is lost when the disk is powered down and it is thus necessary to redo this at each for each start up.
    To install hdapm so it is launched at each start-up, it is necessary to copy hdapm to the hard drive (/usr/local/bin is advised) and to copy the file hdapm.plist in /Library/LaunchDaemons.
    It will be can be necessary to you to edit hdapm.plist with the desired parameters; the default settings are: the repertory where hdapm is /usr/local/bin, the hard drive is regulated on the first (disk0) and the level of APM is the maximum.
    You can simply copy the file hdapm into /usr/local/bin file if you want to avoid modifying Plist.
    Simplest way to reach these files is to use the Go/go to the file and to copy/paste this address before validating.

    Yeah, I don't buy that. I spoke with Seagate a couple of months ago when I was looking for the impossible to find 500 GB 7200 RPM HD and asked them that very thing. They told me it would work fine, but I should disable SMS. Apple told me the same thing. I ultimately waited and got a non G-Force model, but Seagate told me it would work.
    I also don't believe that they'd OEM the drive to Apple knowing it wouldn't work. That makes absolutely no sense. If Seagate knew the G-Force drive would not function properly in an Apple MacBook/MacBook Pro, and they OEM'd it to Apple for that purpose anyway, what does that say about Seagate?
    I admit it's odd that the used the G-Force model given the presence of SMS, but apparently Seagate has prioritized the manufacturing of the G-Force drives and probably offered it to Apple.

  • Where does iWeb save the contents of my website now that iDisk is not available?

    With the latest change to iCloud and iDisk not available anymore, where does iWeb save the contents of websites?
    I looked for the files undel Library/Application Support/....but could not find the iWeb folder.
    Any ideas please?
    Thank you.

    In Lion the Library folder is now invisible. To make it permanently visible enter the following in the Terminal application window: chflags nohidden ~/Library and hit the Enter button - 10.7: Un-hide the User Library folder.
    To open your domain file in Lion or to switch between multiple domain files Cyclosaurus has provided us with the following script that you can make into an Applescript application with Script Editor. Open Script Editor, copy and paste the script below into Script Editor's window and save as an application.
    do shell script "/usr/bin/defaults write com.apple.iWeb iWebDefaultsDocumentPath -boolean no"delay 1
    tell application "iWeb" to activate
    You can download an already compiled version with this link: iWeb Switch Domain.
    Just launch the application, find and select the domain file you want to open and it will open with iWeb. It modifies the iWeb preference file each time it's launched so one can switch between domain files.
    WARNING: iWeb Switch Domain will overwrite an existing Domain.sites2 file if you select to create a new domain in the same folder.  So rename your domain files once they've been created to something other than the default name.
    OT

  • Table Backup into hard disk

    Hi friends,
    Can we take backup of one table into hard disk and can we restore it into database.If possible how ?.
    Thanks in Advnace
    -Srini

    Hi,
    use export import utilities to put one table into the hard disk and restore it back.
    regards
    gaurav

  • How do I move music files from the startup disc to iTunes in the other internal hard disk os 10.5.8?

    How do I move music files from the startup disc to iTunes in the other internal hard disk os 10.5.8?
    The music I want to move was in iTunes but is now just files. I had to reinstall a new iTunes and lost all my old music.
    Thank you!

    That article is about using your iPod as an external hard drive, to move files from one computer to another computer.  It is not related to your question.
    You can't use iTunes to move song files from iPod to computer, except for songs you purchased from the iTunes Store (and you can also re-download purchases).  However, there are third-party methods and utilities that can move song files from iPod to computer.  If you do a Google search on something like "ipod transfer," you should get some links.
    Once the song files are on your current computer, add them to that computer's iTunes library by dragging the files (or folder containing the files) to the iTunes window.  After confirming everything is there (and fixing the data issue you mentioned) you can sync the iPod.  You may want to do a Restore on the iPod, if it might have a data corruption issue, which will erase the iPod's hard drive, re-install the latest software, and set it to defautl settings.

  • Question : is it possible to save the contents of the screen in a graphic object ?

    Assume i asked the machine to plot something (for example within the Function application).Is it possible to save the contents of the screen in a graphic variable (GROB ?) for later reference ?

    Hi!, EmileG: From connectivity kit, connected to HP PRIME, you can ... Copy Screen opens the Screen Shot dialog box from where you copy or, save an image of  the virtual calculator screen.You can leave this dialog box open as you prepare instructional materials and reports that require screen captures  from the calculator.The Screen Shot  dialog box has the following options and buttons:• Border: A slider bar to give the image a boarder and change the thickness, of the border.• Size: A slider bar that changes the size, of the image.• Capture:  Update  the image, to reflect the current state of the  virtual calculator display.• Copy: save  a copy  of  the  current  image to  the clipboard.• Save: save  a copy  of  the  image to  a file. In  this case, you  can specify a name and location  for the saved  file.• Close: close the Copy  Screen  dialog box.

  • How to save the contents of a file(not a text file)

    Hi all, I want to save the contents of a file(,png file, not a text file) as a field in a class. Shall I have it as a string or byte array or something?
    I have tried saving a file in a string but there were some problems with loading the file from a different platform. Following is my code.
            String string;
            try {
                StringBuffer sb = new StringBuffer(1024);
                char[] characterArray = new char[1024];
                BufferedReader br = new BufferedReader(new FileReader(file));
                while(br.read(characterArray) != -1){
                    sb.append(String.valueOf(characterArray));
                br.close();
                string= sb.toString();
            } catch (IOException ex) {
                ex.printStackTrace();
            }and I use the following code to recover the string back to a stream, and save that stream back to a time later.
        ByteArrayInputStream bais = new ByteArrayInputStream(map.getBytes());I realized that because this file is not a text file, the string could cause some problems. But anyone could tell me if I should use a byte array or someting? and how?
    Any help would be appreciated!
    Cheers,
    Jing

    You should use a byte array, and the binary streams (InputStream a& OutputStream). Never use Strings and Reader/Writer if you have binary data.
    Kaj

  • I want to back up an Iphone 3G and put all the content into Iphone 4. When Iphone 4 is connected to Itunes I do not get an Option to restore from Iphone 3G. IOS 3G - 4.2.1

    I want to back up an Iphone 3G and put all the content into Iphone 4. After I have backed up the Ipone 3G and then when Iphone 4 is connected to Itunes I do not get an Option to restore back up from Iphone 3G. The only devive is see in the drop down list is my Iphone 4. The IOS on Iphone 3G is 4.2.1 and on Iphone 4 is 4.1.
    Please share if anyone has any solution to such a problem.

    You will first have to update your iPhone 4 in order to restore it from the backup of your 3G. Follow the directions here:
    http://support.apple.com/kb/HT4972
    This is an erase/restore deal, so make sure all of your data is on your computer before you begin. iOS 6.1.2 will be installed on your iPhone 4.
    Once done, on your iPhone 4: Settings>General>Reset>Erase All Content & Settings. You'll now be able to restore your 3G backup to your iPhone 4.

  • How do I save the contents of all of my saved mail folders?

    How do I save the contents of all of my saved mail folders?

    Oh, I see...
    All the mail is stored in ~/Library/Mail (and its associated subdirectories).
    Your Library holder is hidden by default under Mountain Lion (and Lion, too?), so hold the Option key when selecting the Window menu in the Finder to add it to the menu, from where you can access it.

  • About the amount of hard disk memory used during Testdrive installation

    Dear all,
    I have a question about installing SAP Netweaver Testdrive on Redhat Linux Enterprise 5.3. Currently I have a virtual machine (sun virtualbox) where Windows Vista is host and the guest operating system is RHLE 5.3 (32 bit). For doing several tests I would like to install the Testdrive on this linux system. Yet, the total available virtual hard disk memory is about 15 GB and I have already used more than 6GB.
    Is there any way to specify the amount of hard disk memory used by Netweaver once it installs DB2 on the system? Because as it seems to me it takes more than 15 GB just for the database. But I'm not sure whether the whole space is really needed, particularly in my case where the aim of use is just for ABAP development and tests (for self-training).
    Thanks in advance,
    Kind Regards,
    Dariyoosh
    Edited by: dariyoosh on Dec 5, 2009 11:23 AM

    Hi,
    You can refer the specific installation guide for the minimum disk space requirement.
    Whatever functionality you use you need minimum space as mentioned in the installation guide.
    You can configure slightly more memory than given in the installation guide to be safer.
    Cheeers...,
    Raghu

Maybe you are looking for

  • How do I delete a movie from my iPhone 5s

    How do I delete a movie from my iPhone 5s.  I have tried swiping it to get a delete message, but it's not working.  Help!

  • How do I get Back to my Mac to work in icloud??

    Ok so I have iCloud... I have a Mac at work and a mac at home - How do I get to use Back to my Mac - I use dto use it in MobileMe, which now doesn't work but I can't seem to get it to work in iCloud... Help????

  • How to remove an account from my mac book pro

    I have a mac book pro, and I think it was a return from someone else, because when I got it it had an app store account on it that isnt mine, and I need to know how to remove it, can anyone help. thanks.      -A

  • Interesting siri bug.....?

    I tried to create a calendar entry today for a John Smith. But siri refused until I told her which of the 25 "johns" I have in my address book is the right one. Trouble is John Smith isn't in my address book and never will be! Its a one off appointme

  • How to play podcasts on your tv with the new Podcast app

    Since with iOS 6, the podcasts were removed from the music app, I can't play video podcasts on my tv using the tv out cable anymore. Same is try for iTunes U clips, they don't appear in the Movies app anymore. I used to download them using Podcast or