Open files with java

Hi I'd like to know if there's a way that you can open a file that's been associated with your java app. I know how to read from a file and I know how to pass command line arguments but what I don't know is how to open my app with a file just by clicking it in my file browser. If needed i could settle for a Mac-specific and a Windows-specific method.

This is nothing to do with Java, and specific to the OS you're installing to. This question comes up quite regularly, from people who are under the impression it's the responsibility of their app to enforce the file association. It isn't. Your installation should ask users if they want the association made. Remember how annoying it is when something you've just installed takes over the file associations of another app, without asking? Don't do it, your users won't like it

Similar Messages

  • I can't open or save file with Java Web Start

    Hi,
    i can't open or save file with Java Web Start:
    import java.io.*;
    import java.util.*;
    public class MetaDataFileCreator {
    public String fileNameSpace = null;
    public String fileName = null;
    protected Properties file = null;
    public MetaDataFileCreator(String fileNameSpace, String fileName) {
    this.fileNameSpace = fileNameSpace;
    this.fileName = fileName;
    public void createMetaDataFile() {
    try {
    System.out.println("file METADATA");
    ClassLoader cl = this.getClass().getClassLoader();
    String nameFileMetaData = fileNameSpace + fileName + ".txt";
    FileOutputStream fileOS = new FileOutputStream(cl.getResource(nameFileMetaData).getFile());
    file = new Properties();
    file.setProperty("aaaaa", "aaaa");
    file.store(fileOS, "");
    fileOS.close();
    } catch (Exception e) {
    System.out.println("Error writing metadata-file: " + e);
    System.exit(1);
    e.printStackTrace();
    I have try also to open a file like this:
    ClassLoader cl = this.getClass().getClassLoader();
    file.load(cl.getResourceAsStream(nameFile));
    also like this:
    try {
    fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
    fss = (FileSaveService)ServiceManager.lookup("javax.jnlp.FileSaveService");
    } catch (UnavailableServiceException e) {
    fss = null;
    fos = null;
    System.out.println("Error with JNLP");
    System.exit(1);
    if (fss != null && fos != null) {
    try {
    // get a FileContents object to work with from the
    // FileOpenService
    FileContents fc = fos.openFileDialog(null, null);
    //FileContents newfc2 = fss.saveAsFileDialog(null, null, fc);
    // get the OutputStream and write the file back out
    if (fc.canWrite()) {
    // don't append
    os = fc.getOutputStream(false);
    } catch (Exception e) {
    e.printStackTrace();
    also like this:
    File f = new File((System.getProperty("user.home")+"x.txt").toString());
    FileOutputStream fileX = new FileOutputStream(f);
    OutputX = new PrintWriter(new BufferedWriter(new OutputStreamWriter(fileX, "UTF8")));
    OutputX.println(....
    but it doesn't work with Java Web Start.
    Can someone help me?
    How can I open or save file?
    thank you.
    Sebastiano

    Did you specify <all-permissions/> in your JNLP file? Did you sign your code? What error are you getting?

  • Opening files with servlet

    Okay... I'm new to using servlets. Not so much to jsp, just to using servlets. I have one process on our site that is using servlets and I'm trying to mimic how that is using em but am having no luck.
    I am trying to open files with a servlet. I have the class built and compiled, but mainly pulled it from Java World. I evenually will need to pass the servlet the filename and path I want open but in this example it has the file set. My problem is I want to send users to a jsp file where I check user authentication and call the servlet to open the doc, but I don't know how to call the servelet or what to send it. If someone could maybe walk me through this.
    Here's my servlet:
    package cmxx.fileServe;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class fileServe extends HttpServlet {
    final static String CONTENT_TYPE_DOC = "application/msword";
    final static String CONTENT_TYPE_HTML = "text/html";
    final static String document = "/docs/form_41.doc";
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    doGet(request, response);
    public void doGet (HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    PrintWriter out;
    out = response.getWriter();
    HttpSession websession = request.getSession(true);
    response.reset();
    response.setDateHeader ("Expires", 0);
    response.setDateHeader("max-age", 0);
    try {
         response.setContentType(CONTENT_TYPE_DOC);
    FileInputStream fileInputStream = new FileInputStream(document);
    ServletOutputStream servletOutputStream = response.getOutputStream();
    int bytesRead = 0;
    byte byteArray[] = new byte[4096];
    while((bytesRead = fileInputStream.read(byteArray)) != -1) {
         servletOutputStream.write(byteArray, 0, bytesRead);
    servletOutputStream.flush();
    servletOutputStream.close();
    fileInputStream.close();
    } catch(Exception ex) {
         throw new ServletException(ex.getMessage());
    } /* end doget */
    } /* end class */

    I'm trying a new servlet. But am getting a few compile errors. Can someone help?
    Here are my Errors:
    43 cannot resolve symbol
    symbol : class URL
    location: class cmis.fileServe.fileServe2
    URL url = new URL(fileURL);
    ^
    43 cannot resolve symbol
    symbol : class URL
    location: class cmis.fileServe.fileServe2
    URL url = new URL(fileURL);
    ^
    57 cannot resolve symbol
    symbol : class MalformedURLException
    location: class cmis.fileServe.fileServe2
    } catch(final MalformedURLException e) { 
    ^
    Code:
    package cmis.fileServe;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class fileServe2 extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    ServletOutputStream out = res.getOutputStream();
    // Set the output data's mime type
    res.setContentType( "application/pdf" ); // MIME type for pdf doc
    // create an input stream from fileURL
    String fileURL = "http://www.adobe.com/aboutadobe/careeropp/pdfs/adobeapp.pdf";
    // Content-disposition header - don't open in browser and
    // set the "Save As..." filename.
    // *There is reportedly a bug in IE4.0 which  ignores this...
    res.setHeader("Content-disposition", "attachment; filename=Example.pdf" );
    // PROXY_HOST and PROXY_PORT should be your proxy host and port
    // that will let you go through the firewall without authentication.
    // Otherwise set the system properties and use URLConnection.getInputStream().
    BufferedInputStream bis = null;
    BufferedOutputStream bos = null;
    try {
    URL url = new URL(fileURL);
    // Use Buffered Stream for reading/writing.
    bis = new BufferedInputStream(url.openStream());
    bos = new BufferedOutputStream(out);
    byte[] buff = new byte[2048];
    int bytesRead;
    // Simple read/write loop.
    while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
    bos.write(buff, 0, bytesRead);
    } catch(final MalformedURLException e) {
    System.out.println ( "MalformedURLException." );
    throw e;
    } catch(final IOException e) {
    System.out.println ( "IOException." );
    throw e;
    } finally {
    if (bis != null)
    bis.close();
    if (bos != null)
    bos.close();
    } /* end class */

  • Process.start("winword", filename) can not open file with space in the path and name

    Hi,
    I am trying to write a class which can open file with selected application. for simplicity, now I just hard code the varaibles.
    the problem: if the path or file name has space in it, even it exist, winword still can not open it.
    could someone kindly show me what I did wrong and how to do it properly.
    Thanks in advance.
    Belinda
    public static class FileOpen
    public static void info()
    string path = @"c:\a temp folder\aaa 1.txt";
    if (File.Exists(path))
        // the file I am using in the sample does exist
         MsgBox.info("yes");
    else
         MsgBox.info("no");
    // working
    //Process.Start("winword", "c:\\aaa.txt");
    // not working
    //Process.Start("winword", "c:\aaa.txt");
    // not working
    Process.Start("winword", "c:\\a temp folder\\aaa 1.txt");
    // not working
    Process.Start("winword", path);

    string AppPath;
    AppPath = ReadRegistry(Registry.CurrentUser, "Software\\FabricStudio", "TARGETDIR", value).ToString() + @"help";
    string FileName = "'"+ AppPath + "\\ImageSamples.doc" + "'";
    try
    System.Diagnostics.Process.Start("Winword.exe", FileName);
    can any body please help for this.
    where i am making mistake?

  • Snow Leopard 10.6.2 CS4 InDesign can't open files with a "#" in file path

    Snow Leopard 10.6.2 CS4 InDesign can't open files with a "#" in file path using any of these perfectly normal methods:
    1. double-click file in the Finder (e.g in a Folder on your Mac or on your Mac desktop etc.)
    2. select file and choose "File... Open" command-o in the Finder
    3. drag file to the application icon in the Finder.
    4. Select file in Bridge and double-click, choose File.. Open.. or Drag icon to InDesign icon in dock.
    If you try to open an ID file named with a "#", you will get an error message "Missing required parameter 'from' for event 'open.'"
    This happens to any InDesign file that has a "#" (pound sign, number sign, or hash) in the filename or in the file path (any parent folder).
    To reproduce
    Name an InDesign file Test#.idd Try to open it in the Finder or Bridge (as opposed to the "Open" dilaog of InDeisng itself).
    "Solution"
    The file WILL open using File... Open... command-o while in InDesign application.
    Rename the file or folders that have a "#" (shift-3) in the filename.
    Report to Adobe if it bugs you.
    This does not occur in "plain" Leopard 10.5 nor Tiger 10.4
    Untested in Panther or before and
    Untested with CS3 and earlier in Snow Leaopard.
    Anyone have those and want to try this... ?

    In case this really bothers you: we've added a workaround for this into Soxy. If you enable the option, these documents will open fine on double-click.
    You need Soxy 1.0.7 from:
    http://www.rorohiko.com/soxy
    Go to the 'Soxy' - 'Preferences' - 'Other' dialog window, and enable 'Open InDesign via Script'
    (Irrelevant background info (it's all invisible to the user): the workaround works by special-casing how Soxy opens documents in InDesign: instead of using AppleScript, Soxy will use ExtendScript to instruct InDesign to open the document - which works fine).

  • Opening files with Illustrator and photoshop doesn't work, i have to drag the files from finder in to the program. This problem appears after opening 4 a 5 files.

    Opening files with Illustrator and photoshop doesn't work, i have to drag the files from finder in to the program.
    This problem appears after opening 4 a 5 files, rebooting helps another 4 a 5 times and appears again.

    I'd recommend reposting in the Boot Camp forum, that is where the Boot Camp and Windows gurus hang out.
    Good luck.

  • Adobe Bridge CC crashes when opening file with Photoshop CC or Camera RAW!

    Adobe Bridge CC crashes when opening file with Photoshop CC or Camera RAW!
    - Tried to Reset the preference with CTRL + Click.
    - It's just new clean install didn't do anything with it yet.
    - Windows 8.
    Any help?

    Just that one project, or any project?  Can you create new projects?

  • Photoshop CS6 (Mac) crashes when opening files with type or using the type tool

    Hi,
    Photoshop CS6 keeps crashing when using the type tool or when opening files with type on it. I've quit suitcase, disabled the suitcase plug-in, reset the preferences in Photoshop there's no crash report coming up either the application just dies! I am currently trying a system restore from time machine to see if that works!. Any other suggestions would be greatly appreciated.
    Many thanks
    Olly

    http://blogs.adobe.com/crawlspace/2012/07/photoshop-basic-troubleshooting-steps-to-fix-mos t-issues.html
    http://helpx.adobe.com/photoshop/kb/troubleshoot-fonts-photoshop-cs5.html

  • Can´t open files with camera raw

    Hi!
    I use Adobe Photoshop CS3 and the option to open files with Camera Raw is disabled in Bridge and in PS.
    Can anyone help?

    While each situation can be different this has been discussed on several threads. Scan down the list or do a search. If you can't find the answer, post a note.

  • Indesign opens files with no space between each word, this happened after a mac update, help?? I don't want to have to go through and manually do it.

    indesign opens files with no space between each word, this happened after a mac update, help?? I don't want to have to go through and manually do it.
    thanks in advance!

    If you are unable to enter the passcode into your device, you will have to restore the device to circumvent that passcode.
    Is the music purchased from iTunes? If it is you can contact iTunes support and ask them to allow you to re-download the music that you purchased from iTunes.
    Also, do you sync the device regularly? When syncing an iPod Touch/iPhone a backup file is made. That backup file doesn't contain your music but it does contain your address book, application data, pictures, notes, etc. After restoring your device, you can try restoring from the last backup that was made of your device so you will not have to start over completely from scratch.
    Hope this helps!

  • How to use parameter file with java

    Is it possible to use a parameter file with Java, and is there any class/method to make it easy to call and use these parameter from a text file, other than scanning the whole text file manually as we can do normally with visual basic/c++, so we can call the program with the parameter file, like java testing c:\\testing.ini

    If I understand you correctly, you may be looking for a properties file. This is basically a text file that contains pairs of strings in the form:
    parameter1=value1
    parameter2=value2
    parameter3=value3
    ...etc.
    and the values are retrieved using the java.util.Properties class - see:
    http://java.sun.com/j2se/1.3/docs/api/java/util/Properties.html
    Sample use://Call chis method once, to load the props file.
    //props file is called "demo.properties", and is
    //in a directory that is included in the classpath
        private void loadMyProperties() throws Exception
         InputStream stream = getResourceAsStream("/demo.properties");
         if(stream == null)
             throw new Exception("stream is null!");
         demoProperties = new Properties();
         demoProperties.load(stream);
         stream.close();
    // Then you can retrieve properties in your code using:
    String param3 = demoProperties.getProperty("parameter3");
    //...etc

  • Unable to open PDF files with Adobe Reader, Mac trying to open files with Quicktime instead, but not succeeding. HELP!

    Unable to open PDF files with Adobe Reader, Mac trying to open files with QuickTime instead, but not succeeding. HELP!

    Hi BDAqua,
    Thanks for the info, I dragged a PDF to desktop ctrl-, get info. change all to open with adobe.
    Problem solved, many thanks for a quick response.
    Barry69

  • Developer: How can I let people open files with my program?

    Hello Everyone,
    I just finished my program for the Mac, and decided to make it an application.
    I used Platypus to make my program into an application. Unfortunately when I try to open a file with my program (control + click on file + open with -> other), my application is grayed out and I can't select it. I see it there along with the other applications but I can't select it like I can Mail or TextEdit.
    I read somewhere I had to use XCode to let people open files with my program but I have never used XCode and I have no idea how to do that. Any help would be appreciated.
    Thanks,
    Nick

    You've posted in the wrong forum. This is the OS X Leopard Installation and Setup forum. You need to post your problem in the Developers forum. Also, since Platypus is not an Apple product, you should visit it's developers forum for assistance. The Apple Discussions is intended to assist users with problems and questions about Apple products only.
    To use XCode Tools you need to install it from the Optional Installs folder on your OS X Installer Disc One. It comes with documentation. More assistance can be found at developer.apple.com.

  • Can't create log file with java.util.logging

    Hi,
    I have created a class to create a log file with java.util.logging
    This class works correctly as standalone (without jdev/weblogic)
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.logging.*;
    public class LogDemo
         private static final Logger logger = Logger.getLogger( "Logging" );
         public static void main( String[] args ) throws IOException
             Date date = new Date();
             DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
             String dateStr = dateFormat.format(date);
             String logFileName = dateStr + "SEC" + ".log";
             Handler fh;          
             try
               fh = new FileHandler(logFileName);
               //fh.setFormatter(new XMLFormatter());
               fh.setFormatter(new SimpleFormatter());
               logger.addHandler(fh);
               logger.setLevel(Level.ALL);
               logger.log(Level.INFO, "Initialization log");
               // force a bug
               ((Object)null).toString();
             catch (IOException e)
                  logger.log( Level.WARNING, e.getMessage(), e );
             catch (Exception e)
                  logger.log( Level.WARNING, "Exception", e);
    }But when I use this class...
    import java.io.File;
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.logging.FileHandler;
    import java.util.logging.Handler;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.logging.XMLFormatter;
    public class TraceUtils
      public static Logger logger = Logger.getLogger("log");
      public static void initLogger(String ApplicationName) {
        Date date = new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
        String dateStr = dateFormat.format(date);
        String logFileName = dateStr + ApplicationName + ".log";
        Handler fh;
        try
          fh = new FileHandler(logFileName);
          fh.setFormatter(new XMLFormatter());
          logger.addHandler(fh);
          logger.setLevel(Level.ALL);
          logger.log(Level.INFO, "Initialization log");
        catch (IOException e)
          System.out.println(e.getMessage());
    }and I call it in a backingBean, I have the message in console but the log file is not created.
    TraceUtils.initLogger("SEC");why?
    Thanks for your help.

    I have uncommented this line in logging.properties and it works.
    # To also add the FileHandler, use the following line instead.
    handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandlerBut I have another problem:
    jdev ignore the parameters of the FileHandler method .
    And it creates a general log file with anothers log files created each time I call the method logp.
    So I play with these parameters
    fh = new FileHandler(logFileName,true);
    fh = new FileHandler(logFileName,0,1,true);
    fh = new FileHandler(logFileName,10000000,1,true);without succes.
    I want only one log file, how to do that?

  • [Flex mobile] Open file with a Filebrowser

    Hi everyone,
    i want to be able to open files with a file browser in my app, but the browse dialog which is opened by the File.browse() method only displays / opens music or image files. Furthermore im not even able to change the Dialog header when running my project on android:
    dir.browseForOpen("Please select a file");
    this doesn't work on android, neither does the next code-block:...
    var dir:File=new File(File.userDirectory.url+ "/geoforms");
    var filter:FileFilter=new FileFilter("Documents","*.txt");
    dir.browseForOpen("Please select a file",[filter]);
    So what do i have to do, to be able to show a decent file select dialog ?

    Nobody any idea?
    i tried it like its described in this article:
    Declaring file type associations
    http://livedocs.adobe.com/flex/3/html/help.html?content=File_formats_1.html
    but i can't get it running for my mobile project. The  type associations works fine in my desktop air application but it doesn't work in my mobile app. Is this  type associations stuff supposed to be working on mobile devices / android?

Maybe you are looking for

  • Getting Error while Creating Sitemap using SitemapGenerator 2.1.1

    Hi, I have configured the sitemap generation for CRS Data by referring Endeca Sitemap Generator Developer's Guide Version 2.1.1.So, I am facing following issue mentioned below, [INFO: No navigation links (defined in the NAVIGATION_PAGE_SPEC_LIST para

  • How do I add pages to a photo book with the same number of photos per page.

    I want to add a photo book, select all the pages and tell the book to be 4 photos per page. And when I add new pages, I want those to have 4 photos. When ever I add, it just selects a random page and then I have to manually change that page to have 4

  • File and Class Communication

    It seems the program file and class file are not talking. I get this message inside program file: # 1120: Access denied; undefined property: myProduct. It applies to these statements: myProduct.setQuantity(3); myProduct.setPrice(2.99); myProduct.setD

  • (V7.X ~ V8.X) OPS 환경의 WAIT EVENT DFS ENQUEUE LOCK ACQUISITION에 대하여

    제품 : ORACLE SERVER 작성날짜 : 2004-08-13 (V7.X ~ V8.X) OPS 환경의 WAIT EVENT DFS ENQUEUE LOCK ACQUISITION에 대하여 ========================================================================= PURPOSE 이 자료는 OPS 환경에서 V$SESSION_WAIT 뷰에 나타나는 'DFS lock acquisition'과 'D

  • Sticky Browser Request

    Dear All, We have a custom build application running on clustered WAS 6.0 with IHS as a proxy. We have come across a strange behaviour with our application. Our application has a authentication page and every user should supply password to access our