JFileChooser to save Files

I am creating an application where I want to give the user an option to navigate through his file system to save a text file in his desired location. can i use JFileChooser for that? if yes then how...please provide a hint...

[How to Use File Choosers|http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html]

Similar Messages

  • Is There Any Component Similar To JFileChooser To Save Information In File

    Hi All,
    I have an application in JSP where I need to save the some information from my jsp page into a file.Like JFileChooser opens the required files, is there any component similar to JFileChooser to "save" the information into a file???
    Thanks In Advance,
    Anupama M

    That's easy :) You can write it yourself.
    Imagine you've a List<Dto> where each DTO represents one row. Create a StringBuilder (or StringBuffer if you're still not at Java 1.5) and append each row value to it. Eventually add separators (comma, semicolon, etc) to it. After each row, eventually add a newline. On the end, stream the contents of the StringBuilder to the HttpServletResponse#getOutputStream(). Don't forget to set the headers accordingly.

  • JFileChooser: save file?

    I'm trying to use a JFileChooser to save a file. But in the JFileChooser I see "Open" and "Cancel". How can I change this to eg. "Save as" and "Cancel"?

    Still not reading the API then?
         setApproveButtonText(String approveButtonText)

  • How to open and save file like the Notepad Demo do?

    I am a newer to Java Web Start. I found that in the Notepad Demo, when user try to open or save file, a message box appear and give the user some security suggestions.
    In my application, I used a JFileChooser and set the <security> element to <j2ee-application-client-permissions/> in the jnlp file. But the application will thow an exception:
    access denied (java.io.FilePermission C:\Documents and Settings\Administrator\desktop\Java Web Start.lnk read)
    Can someone tell me how to solve this problem. By the way, where can I find the source of the Notepad Demo. I want my application to open and save file just like the Notepad Demo do.

    The Notpad demo uses the JNLP api to read and write files. The api doc can be found at:
    http://java.sun.com/products/javawebstart/docs/javadoc/index.html
    Although the Notpad demo source is not available, there is other sample code available at:
    http://developer.java.sun.com/developer/releases/javawebstart/
    Included here is the webpad demo, which uses the FileOpenService and
    FileSaveService API's.

  • JFileChooser interpreting zip file as a folder

    I have an app that reads and writes data to zip files. When opening one, I use a JFileChooser with a file filter for zips and directories.
    This works fine except except on XP. If the zip file is on a remote (Novell) file server, the JFileChooser treats the zip file as a directory. You can't open the zip file itself.
    If the client is W2k, there is no problem.
    I'm using JRE 1.4.1.
    Anyone know if there's a tweak to XP to fix this?

    JResourceBrowser is a swing component similar to the javax.swing.JFileChooser but letting the user navigating into a set of directories bound to various protocols or containers. For an usage sample, listing an ftp directory, creating a new file and editing it inside your application. JResourceBrowser is provided by default with a set of "managers" dedicated to ZIP and JAR, FTP and WebDAV.
    http://www.swingall.com/jrb/index.html
    Features :
    * JavaBeans
    * Built with a GridBagLayout
    * Create your own plugins for navigating
    * User Interface delegate for rendering a file
    * Cutomize the set of actions
    * Default actions for creating a new file, deleting, renaming or locking/unlocking
    * Extracting or putting a file content
    * Save/restore the user interface state
    * ZIP, JAR support
    * FTP support
    * WebDAV support
    * JDK 1.4 and 1.5 compatibility

  • Suggest a filename extension in a save file dialog

    Hello guys,
    does any of you know, how to suggest the user a certain filename extension in a save file dialog?
    I'm using both the normal save file dialog:
         javax.swing.JFileChooser.showSaveDialog,
    and the Java Web Start save file dialog:
         javax.jnlp.FileSaveService.saveFileDialog.
    For both ways I seem not to be able to suggest the user a certain extension for the filename.
    For the normal dialog, I call setFileFilter on the JFileChooser instance.
    The filter shows up in the dialog, and is used by default, but when the user types a name and approves, the returned filename does not have the extension added.
    Of course I can add the extension programmaticaly, but not when inside the JAWS sandbox.
    For the JAWS dialog, I pass an array containing my extension, but it is ignored as if I didn't specify any extensions. The API specs already say that this parameter "might be ignored by the JNLP Client".
    So how to tell the user what extension to use?
    More people must have encountered this problem.
    I'm making an application that saves and opens xml files and exports html files.
    I'm using this code to test the behavior:import java.io.ByteArrayInputStream;
    import java.io.File;
    import javax.jnlp.FileContents;
    import javax.jnlp.FileSaveService;
    import javax.jnlp.ServiceManager;
    import javax.jnlp.UnavailableServiceException;
    import javax.swing.JFileChooser;
    import javax.swing.filechooser.FileFilter;
    public class ChooseFile
        static final String[] EXTENSIONS = { "xml" };
        static final String DESCRIPTION = "XML files";
        public static void main(String[] args)
         try {
             ServiceManager.lookup("javax.jnlp.FileOpenService");
             // we're running with JAWS
             System.out.println("JAWS filechooser:");
             System.out.println(choose_JAWS());
         catch (UnavailableServiceException x)
             // we're NOT running with JAWS
             System.out.println("normal filechooser:");
             System.out.println(choose_normal());
        static String choose_normal()
         JFileChooser fc = new JFileChooser();
         fc.setFileFilter(new CustomFileFilter(EXTENSIONS, DESCRIPTION));
         if (JFileChooser.APPROVE_OPTION == fc.showSaveDialog(null))
             return "selected " + fc.getSelectedFile().getName();
         else
             return "cancelled";
        static String choose_JAWS()
         try {
             FileSaveService fos = (FileSaveService)ServiceManager.lookup(
                         "javax.jnlp.FileSaveService");
             ByteArrayInputStream stream = new ByteArrayInputStream(new byte[] {});
             FileContents fc = fos.saveFileDialog(null, EXTENSIONS, stream, null);
             if (fc != null)
              return "selected " + fc.getName();
             else
              return "cancelled";
         } catch (Exception x)
             x.printStackTrace();
            return "";
    class CustomFileFilter extends FileFilter
        String[] extensions;
        String description;
        public CustomFileFilter(String[] extensions, String description)
         this.extensions = extensions;
         this.description = description;
        public boolean accept(File f)
         if (f.isDirectory())
             return true;
         String extension = getExtension(f);
            if (extension == null)
                return false;
         for (int i=extensions.length; i-->0; )
             if (extension.equals(extensions))
              return true;
         return false;
    public String getDescription()
         return description;
    private String getExtension(File f)
    String ext = null;
    String s = f.getName();
    int i = s.lastIndexOf('.');
    if (i > 0 && i < s.length() - 1)
    ext = s.substring(i+1).toLowerCase();
    return ext;
    }Any help is greatly appreciated!
    Tom Jansen

    @tjacobs01
    Hi Tom,
    I have a question regarding your classes
    tjacobs.ui.fc.FileExtensionFilter and
    tjacobs.ui.fc.FileChooser.
    When I look at your code, I see the filename extension is appended in showSaveDialog:     public int showSaveDialog(Component c) {
                        setSelectedFile(new File(f.getAbsolutePath() + "." + ((FileExtensionFilter)filter).getType()));
        }It gets the extension by calling getType on the filter. But getType is implemented as:    public String getType () {
            return mExtensionList.get(0).toString();
        }So this returns the first type in the list. It does not check what filetype is selected by the combobox.
    Am I missing something?
    Also, in getDescription:    public String getDescription() {
            if (mDesc == null) {
                mDesc = "";
                for (int i = 0; i < mExtensionList.size(); i++) {
                    mDesc += (i != 0 ? ", " : "") + "." + mExtensionList.get(0).toString();
                mDesc+= " files";
            return mDesc;
        }you seem to iterate through the list, but only take the first entry every iteration.
    Can you explain mExtensionList.get(0)?
    Do you know how to test what type is selected in the JFileChooser's combobox?

  • Can not sort the files in JFileChooser if the files are from remote machine

    Hi All,
    Let me set the context of the question.
    I have extended the JFileChooser to support the listing/view of files.dirs etc of remote location through CORBA.To achieve that i have customized
    my FileSystemView to support it. In general ,the current JFileChooser sorts the file when we have details view .My question is related to this.The default
    JFileChooser has the support for sorting but when i customized the FileSystemView,the sorting functionality is no more exist.I tried with TableRowSorter as well but
    the sorting can be achieved in View only,the model still remains same as initial.
    Any pointer towards this will be highly appreciated.
    Thanks
    Praveen

    Can anyone help me out to solve this problem or any suggestion regarding this ?
    Regards
    Praveen

  • Can't save files to Last Folder Used

    I'm scanning items with a Kodak iQsmart3, running under Kodak's oXYgen 2.6.1 scan application. Late last week, the application suddenly stopped saving files to the last folder used. Now I have to re-select the destination folder for each scan.
    I have rebooted the computer several times, and have also re-installed the scan application, but nothing helps the problem. It seems now that the problem may be with OS 10.4.11. I've searched and searched for a solution within the OS, but can't find anything that helps.
    Does anyone have a suggestion on how to proceed? Is there a place where you can check to see if the saving options can be changed?

    Thanks for your suggestion. However, I did as you advised and still cannot save files to the last folder used, as I used to be able to do.
    This is the first time in the 2 1/2 years I've been using this system that I've had any trouble with it. When I opened Disk Utility, it showed me the size and type of three different drives, all identical in manufacture. The first holds the Operating system, and the other two are set up in a Raid Striped set. I selected Macintosh HD under the name of the first drive, since that's the name of the disk on my desktop, and ran the Repair Permissions function, moving the recentitems.plist file to the desktop and rebooting, as per your instructions. Was that the proper area to use or should I have selected the disk description above that?
    (Below is the disk information from the Disk Utility application)
    Disk Description : Hitachi HDS725050KLA360 Media Total Capacity : 465.8 GB (500,107,862,016 Bytes)
    Connection Bus : Serial ATA 2 Write Status : Read/Write
    Connection Type : Internal S.M.A.R.T. Status : Verified
    Connection ID : "Bay 1" Partition Scheme : GUID Partition Table
    (Below is the information on the Macintosh HD folder of that drive.)
    Mount Point : / Capacity : 465.4 GB (499,763,888,128 Bytes)
    Format : Mac OS Extended (Journaled) Available : 226.2 GB (242,855,989,248 Bytes)
    Owners Enabled : Yes Used : 239.3 GB (256,907,898,880 Bytes)
    Number of Folders : 133,296 Number of Files : 684,567

  • I can't save files to my desktop, but I can save anywhere else. How do I fix this?

    I can't save files to my desktop.  I have no problem saving the same file anywhere else.  WHen I try through excel, for example, it tells me the file is read only. When I try to save it as a different file name, a pop up tells me I do not have permission to save to the desktop.  The same issue occurs when I attempt to take a screen shot (default save to desktop)

    Click on it, choose Get Info from the File menu, give yourself Read & Write access under Sharing and Permissions or Ownership and Permissions, and ensure it's not locked.
    (64371)

  • I can't save files to desktop in OS 10.8.2

    is there some reason I can't seem to use the finder to select the desktop to save files to? 

    So, after a couple of hours on the phone with tech support, turns out somehow the desktop folder was being treated as a document type and terminal was the default program to open it.  Never figured out why that could have happened, but had to create a new desktop folder and move all the items from the old desktop into it.  So for the time being the problem is gone.

  • "Always ask me where to save files" does not work.

    Summary: The "Always ask me where to save files" feature does not work. No dialog box comes up, apparently because the browser is stuck on a bad old read-only lastDir location, in a prefs.js file that I can't edit.
    Details:
    I am using Firefox 30.0 on Mac OS 10.6.8. My Mac has a both a read/write Mac partition that I use most of the time, and a bootcamp Windows partition drive ("C"), which I can read but not write to.
    At some point I accidentally tried to download a file from a site, using Firefox, to the read-only Windows C drive. Ever since that time, I have not been able to download any files from Firefox, except to the firefox/downloads folder. This is inconvenient. If, in preferences, I try to set downloads to ""Always ask me where to save files", the dialog box does not come up when I actually try to save files. This problem does not apply to saving photos by right-clicking them.
    If I open, in text-edit, mozilla/firefox/profiles/t4vockvue.default/prefs.js, which was saved yesterday, I can see a problematic line. It reads:
    user_pref("browser.download.lastDir", "C:\\Documents and Settings\\[etcetc]");
    C:\\Documents and Settings\\[etcetc] being the read-only windows directory.
    This prefs.js is apparently not an editable file.
    I tried to fix this by opening a browser tab in Firefox and opening about:config. The editable browser.download.lastDir does NOT show the same "lastDir"....it shows some directory that I successfully downloaded photos to, by right-clicking on a photo.
    How can I fix this problem?
    Thanks.

    To confirm which profile folder is active when you are running Firefox, it is easiest to open it from inside Firefox as follows:
    Sometimes the file that stores the customizations becomes corrupted and fails to update properly at the end of your session. You can rename the file and customize from scratch.
    * "3-bar" menu button > "?" button > Troubleshooting Information
    * (menu bar) Help > Troubleshooting Information
    In the first table on the page, click the "Show in Finder" button (Windows: "Show Folder" button).
    Hopefully you are using a separate profile folder on each OS.

  • Re Time Machine "You do not have appropriate access privileges to save file ".002332b7be8a" warning preventing backups--this may help temporarily

    My TM is often giving me the "You do not have appropriate access privileges to save file “.002332b7be8a” in folder “Time Machine Backups”" message when I go to select my backup drive. I've reviewed past archived discussions on this and, like many other people, gotten completely flummoxed trying to find a permanent solution.  Tried the suggested fixes via Terminal and it didn't help because I couldn't get through the entire process without Terminal telling me it couldn't find a file or drive.  When I can find the time, I'm going to try Tinker Tool to reveal where that numbered file actually is and give it another go.
    In the meantime, for those who are desperate to get their TM working again to get at least one backup done, I can offer people a temporary solution that's worked for me.
    I've found that restarting my iMac somehow resets TM and usually allows it to do at least one of its automatic backups, sometimes several, before it reverts back to failing and producing that same darn warning message.  I only want a backup done once a day, so it's not that inconvenient to go this route.
    There's another even quicker  method (perhaps a little more risky but hasn't been a problem for me yet) that I've been using more recently, and that is to simply unplug the external while the iMac is on (I close system preferences first though, and make sure TM isn't actually doing anything at the time) then plugging it back in and choosing the backup drive again in the TM system preferences window once that drive has shown up again in the Mac's list of devices.  I don't get that warning message when I do this.  It works every time for me and so far it hasn't lost or corrupted any data on the external, despite the warning message you get on Macs when you unplug a USB device without ejecting it first.  However, do this at your own risk--don't flame me if it backfires on you.  If you're of the opinion that it's not wise to unplug the device this way, then fine, go ahead and state such in this thread, but be polite about it.
    Hope this helps anyone who's frantic to make a backup without having to start from square one with a whole new complete initial backup (can take many hours to make one) on a fresh external drive.
    By the way, I've read somewhere that this problem was fixed with Snow Leopard.  Whether that's true is another matter.  I'm not quite ready to update to 10.6 for other reasons, even though I bought it, and I figure some other people are also still using 10.5.8 out of fear and loathing around the unknowns of installing a new OS too, so that's why I thought I'd post this message (couldn't find a discussion around this that was still active and not archived).

    noodlenose wrote:
    My TM is often giving me the "You do not have appropriate access privileges to save file “.002332b7be8a” in folder “Time Machine Backups”" message when I go to select my backup drive.
    Wow, I haven't seen that in a looooong time!
    Tried the suggested fixes via Terminal and it didn't help because I couldn't get through the entire process without Terminal telling me it couldn't find a file or drive.
    Do you mean in #C5 of Time Machine - Troubleshooting?
    When I can find the time, I'm going to try Tinker Tool to reveal where that numbered file actually is and give it another go.
    It should be at the top level of the drive.
    By the way, I've read somewhere that this problem was fixed with Snow Leopard.
    Yes.  I'm not sure if it was 10.6.0 or one of the early updates, but I haven't seen any reports of this in quite a while.

  • I cannot print from Websites or my college online course. Tries to save files to desktop as an .xps document but nothing happens and I get an error message that print command did not work. Have reinstalled firefox and adobe, no help. Any suggestions?

    Cannot print anything from internet using Firefox as browser. Please advise. I have to use Firefox for internet college courses, cannot print my assignments. I do not have this problem on Mac or using Internet Explorer. Only happens when using Firefox. When I select print a message comes up to save information to desktop as .xps file. Select save, sometimes it is on the desktop but I cannot open the file or it simply does not save file and get an error message that print command failed. What is happening?

    {Ctrl + P} and select your printer in the Printer - Name box near the top of that window.
    http://kb.mozillazine.org/Problems_printing_web_pages

  • Microsoft Office 2004 (Word) unable to save files  I have been running Office 2004 on my Intel iMac with Snow Leopard for some time and all of a sudden I cannot save a document. Word just stopped responding and I have to force quit. I can open Word and cr

    Microsoft Office 2004 (Word) unable to save files
    I have been running Office 2004 on my Intel iMac with Snow Leopard for some time and all of a sudden I cannot save a document. Word just stopped responding and I have to force quit. I can open Word and create a new document but I cannot save it. I reinstalled Word but that didn’t help. Then went to the Internet and found at least one other Mac user having the same problem which it suggests is caused by a recent Mac Security Update:
    http://answers.microsoft.com/en-us/mac/forum/macoffice2004-macword/word-2004-wil l-not-open-or-save-documents/b04eb870-9b0d-4f3b-bb47-b122301e36f6
    So I check for a new Mac Security Update and sure enough there was one. I downloaded it and now Word seems to be working, as it should. I can both open and save files. The only problem remaining is that when I open Word I get the following error message “An unexpected error occurred while trying to load the Microsoft Framework library”. I contacted Apple but they were unable to help.
    How can I get rid of this error message?

    Look, I realize you might have to get your machine working, so this is how you revert back.
    Restore proceedure to pre-Security Update 2012-001 v 1.0 & v 1.1
    #1 Backup your personal data off the machine.
    Backup files off the computer (not to TimeMachine). If you don't have a external drive, get one and connect to the USB/Firewire port and simply drag and drop copy your User folder to the external drive, it will copy all your files. It's best to have two backups of your data off the machine when trying to restore.
    Disconnect all drives now to prevent any mistakes from occuring.
    #2 Reinstall OS X 10.6 from disk
    Get out your 10.6 install disk and make sure it's clean and polished (very soft cloth and a bit of rubbing alcohol, no scratches) If your disk is borked, you'll have to order a new one from Apple with your serial number.
    Hold c boot off the 10.6 disk (wired keyboard, internal optical drive), use Disk Utility First Aid to >Repair Disk  of your internal drive  (do not format or erase!!), Quit DU and simply re-install 10.6.
    Note: Simply reinstalling 10.6 version from disk (without erasing the drive) only replaces 10.6.8 with 10.6.x and bundled Apple programs, won't touch your files (backup anyway)  or most programs, unless they installed a kext file into OS X itself. (only a few on average do this)
    #3 Update to 10.6.8 without Security Update 2012-001 v1.0 or v1.1
    Reboot and log in, update to 10.6.8 via Software Update, but EXCLUDE THE Security Update 2012-001 by checkinig the details and unchecking the blue check box.
    #4 Reinstall any non-working third party programs
    When you reboot, make sure to reinstall any programs that require kext files installed into OS X, you'll know, they won't work when you launch them or hang for some reason as they are missing the part they installed into OS X.
    If for some freakish reason you get gray screen at any time when booting (possible it might occur when you reinstall older programs), hold the shift key down while booting (Safe Mode, disables kext files) and update your installed third party software so it's compatible with 10.6.8.
    https://support.apple.com/kb/TS2570
    That's it really.

  • I deleted my download folder and now I can't download anything. I can't select the folder to "save file to" and when I select "ask me where to save files" I still can't download. it says your file will start downloading, but then it doesn't. Help!!

    I deleted the folder that saves everything that is downloaded from Firefox. After that I can't download anymore. I've tried clearing my download history, reset the download folder, reset the download action by renaming the mimetype.rdfs file and it's still not working. I've tried to choose a different download folder but it doesn't let me select any folder at all. If I select "ask me where to save files" and then try and download something, the download doesn't start after I select save to. The only time it does actually download is when I select "open with...windows mediaplayer" when downloading then the download will start. Please help. Thank you.

    You broke your phone by getting it wet.  Nothing more to say.  Bring it in to Apple for an out of warranty exchange or buy a new phone.  There's really nothing else we users here can help you with.

Maybe you are looking for