Problem with opening a file in its application using Runtime

Dear experts,
excuse me for my ignorance, but I am facing a problem and I would really
appreciate some help. I am working on a java program in which I want the user
to have the ability to save the contents of a JTable into a file of his preference (the file could be of any type i.e xls, txt, doc...) and then open this file in its
default application (i.e the txt file through notepad, the xls file through excel etc..).
Everything works fine with the code below, if the filePath does not contain blank spaces. I did some search on the forun and the web, and also tried to
find a solution through the great link
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html but I still
cannot solve the problem. Below I quote the part of the code (actually the actionPerformed dunction of the equivallent button) which is responsible for the opening of the file.
    excelButton.addActionListener(new ActionListener()
       public void actionPerformed(ActionEvent e)
         //saveFileName is the File that I want to open
         String filePath = "\""+saveFileName.toString()+"\"";
         System.out.println(""+filePath);
         try
          String cmd="cmd.exe /C start "+filePath;
          String cmd="cmd.exe /C start C:\\Documents and Settings\\test.xls";
          Process p = Runtime.getRuntime().exec(cmd);
         }catch(IOException ec){}
     });Thank you in advance for your help!
Sincerely yours,
JIM

Dear BillBlalock ,
thank you for answer!! You are very kind and helpful!! I would like to inform everybody that I have finally find another way of soilving my problem and I announce it to the forum in case somebody else encounters the same problem. Well, I soved the nproblem by using the following code:
    excelButton.addActionListener(new ActionListener()
       public void actionPerformed(ActionEvent e)
         String filePath = "\""+saveFileName.toString()+"\"";
         System.out.println(""+filePath);
         try
           String cmd="explorer "+filePath;
           Process p = Runtime.getRuntime().exec(cmd);
         }catch(IOException ec){}
     });I hope it can be useful to somebody!! By this code, I can make a button (in my case the excelButton) to open any file in its default application. Keep up the great work you are doing guys!!

Similar Messages

  • Problem with opening PDF files from JSF page using SDO

    Hi all,
    I'm new with JSF and was attempting to read a PDF file from a Database using SDO and JSF. The code below throws an exception when casting from DataObject to Blob. The getLcDoc() method was created by WSAD when I dragged an SDO relational record onto the JSF page. This method returns an DataObject type which I tried casting to a Blob type before using it further. However, an exception is thrown.
    Any feedback is appreciated.
    Arv
    try {
                   FacesContext faces = FacesContext.getCurrentInstance();
                   HttpServletResponse response =(HttpServletResponse) faces.getExternalContext().getResponse();
                   Blob file= (Blob)getLcDoc().get("ATTACH");
                   int iLength = (int)(file.length());
                   response.setHeader("Content-type", "application/pdf");
                   response.setHeader("Content-Disposition", "inline; filename=Attachment");
                   response.setHeader("Expires","0");
                   response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
                   response.setHeader("Pragma","public");
                   response.setContentLength(iLength);
                   ServletOutputStream os = response.getOutputStream();
                   InputStream in = null;
                   in = file.getBinaryStream();
                   byte buff[] = new byte[1024];
                   while (true) {
                   int i = in.read(buff);
                   if (i<0) break;
                   os.write(buff,0,i);
                   os.flush();
                   os.close();
         } catch(Exception ex){
              System.out.println("Error while reading file : " + ex.getMessage());
         }

    Hi...I found out that there is actually no need to use a Blob object at all. You can simply call the OutputStreams write() method and pass the DataObject.getBytes() method that returns a byte[] array. The revised code is shown at the end of this posting.
    However, a few other teething problems exist:
    1. This works well only if I specify the content type in response.setHeader() method. What if my users upload different types of files, is there a way that the browser opens according to the file type without setting the content type?
    2. I still have a problem opening PDF files, even if I specify - response.setHeader("Content-type", "application/pdf");
    I get the message - The file is damaged and could not be repaired
    3. I would also like this to open the attachment in a new window and using target="_blank" doesn't seem to work as seen below:
    <h:commandLink
                                                 styleClass="commandLink" id="link1" action="#{pc_DocumentDetailsRead.doLink1Action}" target="_blank">
                                                 <h:outputText id="text5" styleClass="outputText"
                                                      value="Click Here"></h:outputText>
                                            </h:commandLink>
    ------------------------Revised code-----------------------------------------
    FacesContext faces = FacesContext.getCurrentInstance();
                   HttpServletResponse response =(HttpServletResponse) faces.getExternalContext().getResponse();
                   response.setHeader("Content-type", "application/msword");
                   response.setHeader("Content-Disposition", "inline; filename=Attachment");
                   response.setHeader("Expires","0");
                   response.setHeader("Cache-Control","must-revalidate, post-check=0, pre-check=0");
                   response.setHeader("Pragma","public");
                   ServletOutputStream os = response.getOutputStream();
                   os.write(getLcDoc().getBytes("ATTACH"));
                   os.flush();
                   os.close();

  • HT1338 I have a problem with opening downloaded files from the internet; zip types. Can you tell me an app to open these types of formats of files?

    I have a problem with opening downloaded files from the internet; zip types. Can you tell me an app to open these types of formats of files?

    It should unzip if you double-cick.
    What are you seeing happen when you do that?
    Select a .zip file in the Finder and Get Info (cmd-i). What is set for it to Open With. It should be Archive Utility.

  • Problem with opening PDF files in Google Chrome browser

    We have a web page displaying links to dynamically generated PDF files located on the internal repository. This files are not just text PDF files but PDF forms created using XFA technology. This means that they must be opened and filled only in Adobe Reader and not in Foxit Reader or browser's built-in PDF viewer.
    Now, the problem is that a Google Chrome browser opens any PDF file using its own PDF viewer. And I want to force this browser to open PDF files in Adobe Reader.
    How can I achieve this without disabling 'Chrome PDF Viewer' plugin since I can't do this for all users of our web site?
    Any help or advice would be greatly appreciated.
    P.S. We use LiveCycle ES3.

    Each user would have to set each browser individually.
    Note: I don't think it's possible to set the default PDF viewer with code for every user who visits the site.
    See the following link to enable Adobe Reader as the default PDF viewer in different browsers:
    http://helpx.adobe.com/acrobat/using/display-pdf-browser-acrobat-xi.html
    Note: Not all PDF viewer browser plug-ins support PDF submissions, and most 3rd party viewers may not support forms created with LiveCycle or forms with Extended Reader Rights enabled.

  • Problem with open PDF files

    update I did, as you've mentioned, and now it works - let's say in 95%  When I receive an e-mail with PDF, I hit "save", and right away I cannot open the file. However, when I will go back to e-mails list, and wiev once again the same e-mail, I can see the PDF directly from the level of mail. Bit strange, however big improvement comparing to the former situation. Perhaps there is some kind of bug in stock e-mail app?

    Hi, I have following problem with my Xperia Z3:- when I receive the e-mail with PDF as attachement, I can just save it, but cannot open it. It says: "you have no application installed, please install one.."- when I save the file, and open it from File Manager, I can easily open it with Acrobat, Foxit or any other. There's no problem- when I try to do the same directly from "Downloaded" apps, again I cannot open it As I receive some part of e-mails with PDF's, the best way would be to open them directly after saving from e-mail client. Saving them, and then going to File Manager to open makes it more complicated.  Do you know, what can be the problem here? It concern stock e-mail client, Android 5.0 Hope you may know some solution

  • Problem with opening pdf files in Explorer

    I'm trying to use a button to open a pdf file. It's always
    worked in the past, but now I'm receiving an "object error" and the
    pdf is not loading. Does anyone know if this is a problem with the
    new version of Internet Explorer? Any work arounds?
    Here's my code:
    on (release) {
    getURL("NameofDoc.pdf", "_blank");
    }

    Hi,
    1. It's Adobe Reader XI, ver 11.0.08
    I guess the version of the plug-in corresponds with the version of the reader itself?
    2. "Page cannot be displayed", mostly
    Some say it takes a while for the (small) pdf to open, but we could no recreate this behavior yet.

  • Does anyone have a problem with opening PDF files in iBook after updating the program recently

    I need to try to open the pdf file a few times before it goes in iBook.
    It is making me look like a fool cos I use iBook for my presentation to my clients

    I'm presumably having a similar problem with pdf's in ibook.  It seemed to work fine until about two updates ago.  We're using ipad II's with ibook (latest version as of today) for our board of director's reports.  These are sometimes several hundred pages and password protected pdf's.  Now the more whiney members of the board are *******' at me, so I need to find a solution relatively quickly.  Is there a way to back off the updates?
    What it does.
    When a PDF is chosen to open from the library, ibook open a "blank" file -- showing only the ibook background.
    One can try closing and re-opening the PDF and after three or four times it'll open -- seems to be random.
    These PDFs are created in Adobe Acrobat 9.

  • Problem with opening doc. files in pages '09

    Hello, can anybody help me, ever since i installed " snow leopard" v10.6.2, pages '09 doesn't open doc. files ( word ) anymore.
    Even documents produced in pages en ""saved as" a word document can't be opened again.
    Keep receiving pop up whit message " can not be opened"
    Yves
    Message was edited by: deschutter

    You need to manually install the 10.6.2 "Combo" version, there were problems with just using the regular update.
    See:
    http://www.freeforum101.com/iworktipsntrick/viewtopic.php?t=153&mforum=iworktips ntrick
    Peter

  • Problems with opening RAW files in PSE7

    Hello all
    I have just upgraded my DSLR from a Sony Alpha 200 to a Sony Alpha 450
    While using the Alpha 200 I had no problems opening RAW files in Elements 7 (Sonts RAW file format = .ARW)
    But now im using the Alpha 450 Elements says it doesnt reconginse (wrong file type) the .ARW files
    Does anyone know the reason for this or a way to correct it?
    Cheers
    J. Black

    Here is the compatibility for ACR versions with Photoshop and Photoshop Elements. I read it in read me file :
    The Camera Raw 6.1 plug-in is not compatible with versions of Photoshop earlier than Photoshop CS5 or versions of Photoshop Elements earlier than Photoshop Elements 8.0 for Windows and Photoshop Elements 8 for Mac.
    • The latest version of the Camera Raw plug-in available for Photoshop Elements 3.0 customers is Camera Raw 3.6.
    • The latest version of the Camera Raw plug-in available for Photoshop Elements 4.0 (Windows) is Camera Raw 3.7.
    • The latest version of the Camera Raw plug-in available for Photoshop Elements 5.0 (Windows) is Camera Raw 4.5.
    • The latest version of the Camera Raw plug-in available for Photoshop Elements 6.0 (Windows, Mac) and Photoshop Elements 7.0 (Windows) is Camera Raw 5.6.
    Hope that helps!
    ~V

  • Adobe Reader 10 problem with opening pdf files

    Ever since I downloaded and installed Adobe Reader 10, I have been unable to open .pdf files from the Internet.  When
    I try to download them, I only the get the option of saving the file, not opening it.  Any help would be appreciated.  Thanks!

    We had similar problems with both the upgrade to 9.4.2 and 10.0.1. We would either get the download/save screen or a black screen would appear and eventually error out and freeze up the machine when we tried to hit pages that loaded pdfs stored in Oracle.  We found the pdfs would load when using Chrome or Firefox.
    We're running winXP SP3 and mainly have users using IE 7 and IE 8.  We were eventually able to solve the problem by doing the following:
    Implementing the code fix outlined in this thread (Response.charset = null;) in the page that pulled pdfs from Oracle: http://forums.adobe.com/message/3476821
    Uninstalling and reinstalling the base version of Reader (9.4.0 or X.0) from users' machines that had gone through the update from 9.x to X.x
    Rebooting the machine after each uninstall or install
    Updating the Reader to either 9.4.2 or 10.0.1
    Now we have users who can successfully load the pdfs from Oracle who are running either 9.4.2 or 10.0.1.
    Hope this helps!

  • I have a problem with opening PDF files downloaded from anywhere!

    I can view them ok in Safari, but when I save and download them, they are displayed with the Preview image and will not open.
    When I click them, a message says that 'the file may be damaged or not recognised by Preview'.
    I have cleaned up my computer (apple help ) but still, the problem remains. I downloaded the same file to my MacBook pro, and it saved it in the usual PDF format, (completely different image from above), and opened perfectly well.
    I have checked the settings in Preview and they seem to be set correctly so that Preview will open PDF files.
    What next?
    I am desperate!
    Jennifer

    See if you can delete any Adobe PDF plugins from /Library/Internet Plug-Ins/. Then quit and re-open your web browser and try again.

  • Problem with opening project file from my friend

    My friend save his project and gave me it on CD. Of course he gave me all needed files like source videos. It's videos from the same type of DSLR clips which I also have. So I making my own movies also with clips in this codes or similar. My DSLR is Canon 600D but DSLR of my friend is Canon 550D - clips from his DSLR are of course also written form my system. So everything seems to be OK.
    Now i try to open this project in my PC but it doesn't work at all. I can see only this message:
    My friend work on CS 5 but I work on CS 6. I don't believe that Adobe Premiere Pro can't open a older type of his project files. Please help.

    Mark Mapes wrote:
    What do you know about the sequence preset your friend used?
    Sequence preset? I don't know anything. But I think that is unneceserry even to know. Because why sequence preset can be important? Preset is only a preset. So I can't see any reason preset was a main problem with it.

  • Problem with opening .wmv files in QuickTime since Snow Leopard upgrade

    Until upgrading to Snow Leopard any .wmv files would open automatically in QT when double clicked.
    I now get an error message which says "QuickTime Player must be installed to run this application".
    I can open the file by launching QT(pro) and opening it from within the player - kind of a long way round.
    Any suggestions what the fix might be would be gratefully received
    Thanks

    Hi,
    try upgrading your Flip4mac plugin to the new Beta version which supports Snow Leopard.
    Regards

  • Problem with opening .dds files

    Hello,
    I have a question about opening a .dds file to make skin for a car in RACE 07.
    I have already installed the NVIDIA DDS plug-in and it used to work on PS CS2. Now I tried it on CS3 and at first it said that it was an unknown file format or something (don't remember the exact error). So I first re-installed the plugin. When that didn't work, I copied the dds.8BI file from the Plug-Ins folder in the CS2 folder to the Plug-Ins folder in the CS3 folder on my external HDD. Then I had the same error on both photoshops: "Could not complete your request because the file-format module cannot parse the file."
    Sorry, if the question was posted on this forum before, but I'm a bit too lazy to check the 2000 topics ;) I did check the FAQ topic, but I didn't find anything there...
    Many Thanks,
    Jan

    First of all: many thanks for your reply :)
    Because I didn't immediatley know what you meant with the TIFF-format and I certainly don't know different kinds of DDS's, I concentrated on your last sentence. I knew for sure the manufacturers of the game wanted (or at least didn't mind if) that the players made custom skins and tracks for the game, so I knew their was a way to do it. So I just googled on "how to skin cars ..." (I didn't do that before I posted this topic because it had worked before with other DDS-files) and the first site I clicked on was the official site of the game, with the templates of all the cars in PSD :D So, now it should work.
    Sorry to have bothered you when the solution was so easy, so thank you very much for your help ;)
    Greetz, Jan

  • Problem with opening packaged file burnt to disc

    When I package my 80 page InDesign document the packaging process itself seems to work fine, but then when I burn the packaged document and links to disc and try to open it from the disc it won't open the InDesign file, it goes so far and then 'freezes' and I end up having to Force Quit the application. Any ideas why this would happen? I'm using CS5.
    Thanks

    You're welcome, but I'm afraid we're running out of good options. I was hoping the crash would be different.
    So, we're here:
    Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
    0   libSystem.B.dylib                  0x911b082e pread$UNIX2003 + 10
    1   ...ple.CoreServices.CarbonCore     0x97a8fb30 BasicRead(FileRecord*, short, long long, unsigned long long*, void*, unsigned long long*) + 952
    2   ...ple.CoreServices.CarbonCore     0x97a8f73f PBReadForkSync + 117
    3   ...ple.CoreServices.CarbonCore     0x97a8f6b6 FSReadFork + 59
    4   DataBaseLib.dylib                  0x010efc17 DBUtils::GetUIDPersistedInterfaces(IDataBase*, IDType<UID_tag>, IDType<ClassID_tag>, IPMPersist*, std::vector<IDType<ImplementationID_tag>, std::allocator<IDType<ImplementationID_tag> > >&) + 125463
    and that means that InDesign's database-reading routines have instructed the operating system to read from a file, and for some reason that read never returns. That is very bizarre.
    read(2) [or in this case, pread(2)], should not block It should read the specified bytes from the file or fail to do so.
    Err, OK, let's go back and look a the sample process graph. I see, it's not blocking. But it is calling pread() over and over again...
    I guess this means InDesign has some sort of logic failure that results in it trying to read something [the same thing?] over and over again.
    Well, I guess it's not so bizarre anymore (at least the operating system isn't misbehaving!). It doesn't really tell us what to do though...
    Have you tried opening the file without updating links? It looks like maybe links are involved, but maybe not.
    Huh.

Maybe you are looking for