How to create new file and popup a Save As Dialog?

I want to create a new file and then popup a Save As Dialog to save the new created file.
I have tried to use the JFileChooser as the following code:
=============================================
JFileChooser jfc = new JFileChooser();
File f = new File("c:\\text.txt");
jfc.setSelectedFile(f);
int returnVal = jfc.showSaveDialog(this);
if(returnVal == JFileChooser.APPROVE_OPTION) {
f = jfc.getSelectedFile();
=============================================
I can't found the created file execute the program, anyone can tell me whats going wrong of my code or give me some advice?
Thanks a lot.

Actally, I want to generate a file and specific the
name and the location to save it.
And solution to do this if don't use the JFileChooser?Use a JFileChooser to choose a file name (you can select the directory and type the filename into a field). Once you have the file name you can open a FileOuputStream or FileWriter and write to the file you have just defined. If this file does not exist then it will be created.
If you want to confirm before overwriting an existing file then just put up a confirm dialog if the file exists (File.exists()).

Similar Messages

  • Before this last upgrade, when I would create a file and do a "Save As" it would always open "My Documents" by default, which is what I prefer. But since the upgrade it opens in some annonomus file, to which I have to go through several steps to get to My

    Before this last upgrade, when I would create a file and do a "Save As" it would always open "My Documents" by default, which is what I prefer. But since the upgrade it opens in some anonymous file, to which I have to go through several steps to get to My Documents, and I can't seem to select the default in my preferences. HELP PLEASE!!!

    Before this update of what software from what version to what version using which OS?

  • How to create a file and store its contents into another file?

    Hi,
    I'm having some trouble trying to create a code where I have to to create a file and store its contents into another file?
    I read the API, but I'm not certain how this file thing works.
    Here's my code so far:
    public static void main(String[] args) throws Exception
              File file = new File("tasks.txt");
              if (file.exists())
                   System.out.println("File already exists");
                   System.exit(0);
              Scanner scan = new Scanner(System.in);
              Scanner scan2 = new Scanner(System.in);
              //Scans the input line by line
              scan.useDelimiter("\\n");
              //Scans the input by tabs
              scan2.useDelimiter("\\t");
              PrintWriter outputs = new PrintWriter("newtasks.txt");
              outputs.print("ok");
              outputs.println(3);
              outputs.close();
         }

    I managed to change my text into uppercase, but how do I store the uppercase content into another file.
    -So this is what I did so far, I took a text file and modified its strings to uppercase.
    -Now I need to put those modified strings into another text file, is there a way where I can do that with my current code?
    -I already tried printwriter, but it doesn't seem to work
    public static void main(String[] args)throws IOException
              //Task[] oneHundredTasks = new Task[100];
              String uppercase;
              String combine;
              Scanner scan = null;
              FileInputStream in = null;
            FileOutputStream out = null;
            PrintWriter output = null;
            try
                 scan = new Scanner(new BufferedReader(new FileReader("tasks.txt")));
                 scan.useDelimiter("\\n");
                 scan.useDelimiter("\\t");
                while (scan.hasNext())
                     if(!scan.hasNext())
                          scan.next();
                     combine = scan.next();
                     uppercase = combine.toUpperCase();
                     System.out.println(uppercase);
            finally
                if (scan != null)
                    scan.close();
            //The program will try the input and output files
            try
                 in = new FileInputStream("tasks.txt");
                out = new FileOutputStream("newtasks.txt");
                int c;
                //The number "-1" is used to indicate that it has reached the end of the stream.
                while ((c = in.read()) != -1)
                    out.write(c);
            finally
                if (in != null)
                    in.close();
                if (out != null)
                    out.close();
         }

  • How to create new user and How can i assign end user roles

    Hi,
    I am new to SAP, please explain how to create end users and their roles
    Thanks
    ravi

    Hi,
    Roles are decided by IT managers. Suppose if Persons who are working in shopfloor or production side
    give authorization to Production order create , change and Confirm like that etc
    1. In role maintenance (transaction PFCG), choose the Authorizations tab page.
    2. To change the authorization data for the transactions assigned to the role, choose Change Authorization Data or Expert Mode for Profile Generation. Otherwise, a dialog box appears in expert mode (see Regenerating an Authorization Profile After Changes).
    Please take telp from Basis person also refer this link,
    http://help.sap.com/saphelp_46c/helpdata/EN/52/6714a9439b11d1896f0000e8322d00/frameset.htm
    Thanks

  • How to create new country and cities under country?

    hello,
    i am using 11.5.5 apps version,
    want to create new country and cities under that country, please tell me what is the procedure for that.
    i am using demo vis:
    operations as user.
    Thanks
    yash

    Hi,
    Please check below notes which could be helpful for your issue
    How to Add a New Legal Entity, Ledger and Operating Unit for a New Country [ID 1064366.1]
    How To Create New Countries In The Regions And Zones Form [ID 739798.1]
    How To Enter New Countries or Territories Into The FND_TERRITORIES Table? [ID 341032.1]
    How To Add New Legal Entity Registration Code For Countries That Are Not Available In The List? [ID 604280.1]
    Regard
    Helios

  • How to create new file folders?

    I'm can no longer create new file folders. Can someone help me? I've tried everything.

    Anice, welcome to the forum.
    When requesting help, you should always include the make/model of the computer and/or monitor. This information is necessary for us to review the specifications of them.
    Signature:
    HP TouchPad - 1.2 GHz; 1 GB memory; 32 GB storage; WebOS/CyanogenMod 11(Kit Kat)
    HP 10 Plus; Android-Kit Kat; 1.0 GHz Allwinner A31 ARM Cortex A7 Quad Core Processor ; 2GB RAM Memory Long: 2 GB DDR3L SDRAM (1600MHz); 16GB disable eMMC 16GB v4.51
    HP Omen; i7-4710QH; 8 GB memory; 256 GB San Disk SSD; Win 8.1
    HP Photosmart 7520 AIO
    ++++++++++++++++++
    **Click the Thumbs Up+ to say 'Thanks' and the 'Accept as Solution' if I have solved your problem.**
    Intelligence is God given; Wisdom is the sum of our mistakes!
    I am not an HP employee.

  • How to create new file extension and associate an application with it?

    Hi,
    I want to create a new file extension named ".emsof" and
    associate any text editor with it like notepad++ in windows 8.1
    Moreover all of these files should be searched by having filter of "*.emsof" like any other ordinary files.
    Please guide me about hoe to do it?
    Thanks.

    Hi BurrWalnut,
    Thanks for the help.
    Will this command also allow me create and save file with .emsof extension and  to filter files through .emsof extension (Like we can filter through .doc or .txt extension)???
    1. I don’t know what you mean by ‘filter’. In your initial post you mentioned searching, if that’s what you mean, you can search for any extension.
    2. An easy to understand example of the assoc and ftype commands is a .txt file, which we all use in Notepad:
    Typing assoc .txt in a cmd prompt will return txtfile (the file type).
    Typing ftype txtfile will return %SystemRoot%\System32\notepad.exe %1 (the full path of the program and %1 representing a passed parameter).
    Alternatively, look in the registry hive HKEY_CLASSES_ROOT for .txt and further down for txtfile.
    3. If you add an entry that is later unwanted, you can easily delete it by typing assoc .emsof= and pressing Enter. Then delete the filetype by typing ftype myext= and pressing Enter. You can, of course, just delete the entries in the registry (nor recommended
    for beginners).
    4. Test it out now but be aware not to use extensions or filetypes that currently exist.
    5. Display all extensions and their associated file types by firstly copying the following 4 lines:
    assoc >"%userprofile%\desktop\assoc.txt
    start notepad "%userprofile%\desktop\assoc.txt
    exit
    cls
    Press the Windows Logo key+X (or right-click or press and hold the bottom left corner) and choose Command Prompt/Windows PowerShell (Admin). Using the mouse right-click, paste the 4 copied lines to the Command Prompt window. A .txt file is created on the Desktop
    and Notepad will open and display the list. The list represents the registry keys located in the merged HKEY_CLASSES_ROOT. In the left pane, look for the extension, for example .txt. The (Default) field in the right pane contains the file type, e.g. txtfile.
    6. Now display all file types and their associated programs by substituting the above 4 lines with these:
    ftype >"%userprofile%\desktop\ftype.txt
    start notepad "%userprofile%\desktop\ftype.txt
    exit
    cls
    Another .txt file is created on the Desktop and Notepad will open and display it. This list represents the registry keys in HKEY_CLASSES_ROOT further down beyond the extensions. Look for the file type, for example txtfile, then click or tap shell\open\command.
    In the right pane, the (Default) field shows the full path of the program that opens it, e.g. notepad.
    7. NOTE. In operation, any keys in HKEY_CURRENT_USER\Software\Classes (current user) take precedence over those in HKEY_LOCAL_MACHINE\Software\Classes (all users) and both keys appear as the merged HKEY_CLASSES_ROOT. Any changes should be made to HKCU and
    HKLM. The HKEY_CLASSES_ROOT keys are intended to be read from, not written to.

  • Quickie: Write to measurement file VI, how to create new file?

    I am using the write to measurement file express VI in my code and I have wired into it a control that sets the location to save the measurement file
    The only problem is the measurement file has to exist first!! I cant for example, from the front panel, click the browse directory box, navigate to a folder and type in a name for the file. It just says file not found! Its like the file directory control is opening a file to save to, rather than creating a new file in that location
    How can I solve this?
    Solved!
    Go to Solution.

    Project attached
    If I go in browse options what do i do? Just chose new and existing files?
    Attachments:
    engine.zip ‏119 KB

  • Question: How to create new user and schema in 11g?

    Who can give me answer how to create a new user and schedule?
    I had installed oracle 11g DB and oracle client in my windows OS. I found in the 11g there is no enterprise manager console with new version. It is different from with oracle 10g.So i don't know how to create it new user.
    I had created new DB instance, but i don't how to create a user on that. Who can give me a hand for that? I hope one oracle experenice expert give my answers.
    Thanks a lot!
    Edited by: user774630 on Oct 27, 2008 10:01 PM
    Edited by: user774630 on Oct 27, 2008 10:09 PM

    Hi,
    I am not sure that which option you are talking about? Are you using the EMCA,http://download.oracle.com/docs/cd/B28359_01/server.111/b28319/emca.htm#SUTIL800] to create the new repository for the EM? If not the command line than the other only way is to use DBCA(Database Configuration Assistant).I believe you are talking about that. Yes ,if the message is coming creating the repository than after wards you can login to the EM. You would get the port no of the EM's HTTP port from the $OH/install/portlist.ini file.
    HTH
    Aman....
    Edited by: Aman.... on Oct 28, 2008 11:36 AM
    Gave up, link insertion doesn't work.

  • How to Create text file and ammend that file in SQL Server 2005

    HI All,
    I want to upload some Sql query ouput to .txt file. I have tried using the BCP command.  I am not able to create the .txt file dynamically by running this query.
    First create the bcptest.txt in File System and run the query, then its copying the data.
    But  I want to create .txt dynamically and wants to append the .txt data instead of overwriting.
    EXEC 
     xp_cmdshell
    'bcp "SELECT * FROM sysfiles" queryout "C:\bcptest.txt" -T -c -t,'
    Ram MSBI Developer

    Hi Sebastian,
    I have used the query and it is working fine. but, How could i include the headers of the query also in to the Excel Sheet.
    RehaanKhan. M
    see the method discussed here
    http://sqlblogcasts.com/blogs/madhivanan/archive/2008/10/10/export-to-excel-with-column-names.aspx
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to create new file folders for pics

    My sd card may be corrupt, but I tried to move pictures to new folders and I get the message "Directory full".  How would I normally make new folders so that I can have separate folders for different subjects?

    ssk600 wrote:
    My sd card may be corrupt, but I tried to move pictures to new folders and I get the message "Directory full".  How would I normally make new folders so that I can have separate folders for different subjects?
    Hi ssk600...
    Attach your BB Handheld using the USB and go enable Mass Storage. You should be able to mount the phone with a drive letter on your PC. Once that is done, you can create folders using the Windows explorer shell. Create the folder and move the pictures you want into the new folder using the Explorer in XP or Vista. Once your done managing your new folder and moving your pictures, remove the USB. You will be able to see the new folder once you open up Media icon and menu your pictures on the Media Card.
    H.
    +++++++++++++++++++++++++++++++++++++++++++++++++
    If successful in helping you, please give me kudos in my post.
    Please mark the post that solved it for you!
    Thank you!
    Best Regards
    hmeister

  • How to create new file association

    Hello,
    I have a program that uses the .pez file extension.
    Now I want to change the association so that it is opened with my desired program.
    Therefore I tried:
    xdg-mime default prezi-desktop.desktop application/pez
    However, this does not work. The .pez file is still opened with Fileroller on Gnome 3.
    How do I associate new file types with an application? The program prezi-desktop is not visible in the "Open with" menu. Hence, I cannot change the file association with Gnome.
    Regards,
    Robert
    Last edited by orschiro (2012-12-12 00:27:36)

    Hi there, I refered to this wiki page: Default Applications
    Scroll down and you'll see an section titled "Gnome 3".
    Basically you can try running
    gconf-editor
    and tinkering with settings there.
    Or the more lower-level solution is to dig into either if these files
    /usr/share/applications/defaults.list (global)
    ~/.local/share/applications/defaults.list (per user, overrides global)
    Hope this helps!

  • Illustrator Crashes when creating new file and opening a file

    Every time I try to create a new file, or even open an existing file Illustrator crashes. I have re-installed illustrator...no luck. I have tried running Illustrator while holding SHIFT...no luck. I am using windows 7, and have no crazy drivers that I believe need to be updated.
    Thank you for your help!
    -Patrick

    Have been Googling like always after Illustrator CC crashes with these specific symptoms (Opening fine, New file of Opening existing file crashes).
    All other threads had no working solution for me and the symptoms seemed little different - Opening the program and keeping it open without opening or creating a file was no problem.
    This was the well-appreciated solution that did the trick for me.
    Re: Illustrator CC 17.1 Crashing on New File or Open File (Win 7) works under a different user?
    (In my case I think my default printer had been changed in the background by using a VPN connection this morning which I hardly use ever. Never had been thinking in that direction of course.)
    Good luck to you all.

  • How to create Word file and send file in mail as an attachment

    Hi Guys,
    I want to create report which fetech data from table and create word file of the same data and send file in mail as an attachment.

    Hello Sagar,
    Before posting please use GOOGLE,any way it may help u,
    DivulgeSAP: Send email with PDF, ZIP, TXT etc., as attachment from CL_BCS interface
    Thanks
    Sam

  • How to Create New Hierarchy and Group Codes

    Hi,
    I have a requirement for create New Hierarchy Code and Group Codes...
    Please let me know the procedure of it..
    Thanks...

    solved

Maybe you are looking for

  • Upgrade to 10.6.6 ruins DVD drive - THANK YOU, APPLE!!!!!

    Funny, since the upgrade from 10.6.5. to 10.6.6. I too have problems with a formerly more or less perfect system. I cannot read or write CD-RWs anymore and I've just discovered a data DVD which the MacMini will not read. This was NOT the case before

  • Price changes and lack of customer loyalty prevent me from upgrading.

    I just spoke to two representatives over chat on this site and on the phone.  Bot reps informed me I would have to pay over $30 more per month to simply add a phone line to my account which should only be $10.  They will not go outside the "bundles"

  • How to align output

    How do u align Text in the JOptionPane.showMessageDialog????? like for example: mr. Benjamin singapore mr. christopher malaysia how do we align everything?

  • External Firewire ODD Problem

    Hi~ My Mac mini (PPC) would not recognize external firewire DVD writer. Trial I. System profiler information about firewire of Mac mini shows: Manufacturer - Unknown Model - Unknown Device In my other mac, iMac G5, the attached device information is:

  • Adobe PDF printer - saves output file as filetype+filename need it to save only as filename

    I am using windows xp pro, when i create the pdf file with adobe PDF printer it creates the file name "Ami Pro - filename.pdf"  I really need it to create the file name as "filename.pdf".  Can you please help me - thank you