Assigning a file type to a java program

Greeting,
I'm sorry if this was asked and answered before but I couldn't find it in my (admittedly cursory) search of this forum:
I wrote a program to display a binary file (OK. There are plenty of hex browsers, but I wanted it MY WAY). It works fine. I put in a hook to accept a file name in the command line arguments (argv). That works fine. I can't figure out how to make (in Windows) a file type assignment so that files of extension .bin are opened with this java program.
Can someone give me a hint?

Why don't you just write a batch file that takes a parameter and starts your viewer?
You can then associate the extension with that batch file.

Similar Messages

  • Double-click any file on desktop, calling JAVA PROGRAM

    hi guys,
    i'm breakin my head on doin this prog....when we double click a file icon of any file extension, my another
    java program should be called.
    how to do this???
    pls send a sample code........asap!!!!!!!!!
    regards,
    Sam...

    If you are using windows you could probably make a file association (for all extension types) to a batch file that in turn fires off 'java YourClass params_here'
    - but if you (can) do this, won't you screw up your desktop - ie doubleclicking on an .xls or .doc will never fire up Excel or Word, unless you change the file extension associations back to what they were before? This would make your pc kind of strange to use...??!!
    hi guys,
    i'm breakin my head on doin this
    doin this prog....when we double click a file icon of
    any file extension, my another
    java program should be called.
    how to do this???
    pls send a sample code........asap!!!!!!!!!
    regards,
    Sam...

  • How to extract .sit files(in MAC)  using java program

    Hi,
    please help me , i want to simple program for
    " how to extract .sit files(in MAC) using java program"
    that sit files same as zip files in windows..[                                                                                                                                                                                                                                                                                                                                   

    Thanks for reply...
    but i search in the google about this topic...there is no results will appear..
    the problem is "i have to run program in the MacOS like extract all the
    .sit(StuffIt) extension files. These sit files same as zip files in the windows... we have one tool called StuffIt Expander but it is 3rd party tool. but here requirement is i have to write my own program to extract all the files same as zip file program...
    please do the needful..i am waiting for ur reply,,,

  • Unable to locate existing  file from unix using java program

    Hi
    I have created a file in unix using java program, file.createNewFile();
    And when i try to search for the same file using file.exists() it is returning false. Paths are correct. Can anybody help me out.
    Thanks & Regards,
    Prasanth

    In Linux FC5 using JDK1.6, this code         File temp = new File(System.getProperty("user.home") + "/abcdefghijklmn");
            System.out.println(temp.createNewFile());prints 'true' and the file is created with length zero.

  • How to access database file on CDROM from Java Programe??

    Hello friends,
    I am making online exam application.
    I want my question database to be reside on CDROM.
    but i am not getting any idea how to make DSN or static path that resolute the path that i have mentioned for CDROM.
    basically i want to know how to access CDROM from Java Programe????
    Thanks in advance
    Navik Pathak

    Once you mounted the CDROM (something maybe as /media/cdrom) as a file system (or assigned a drive letter to it like D: or F: or whatever), the files are accessible normally.

  • Changing file type association through java

    hello all,
    here i had a problem like , we know when we try to open .csv file by default it wll open in excel , because the csv file type was associated with excel this we can see in mycomputer->tools->folder options->file types and here we even have the possiblity of changing the association.
    anyway, my question is that is there any way of changing this association like csv to oepn in wordpad through java program
    with regards
    satya

    i created a like wordCsv.reg
    REGEDIT 4
    [HKEY_CLASSES_ROOT\.csv]
    "Default"=string:Wordpad.Document.1
    when i click on this file i could see a message that the entry wassucessfully entried but i cannot see the entry
    is my approach was correct in adding entry in regedit programatically,
    please any more ideas
    http://jniwrapper.com/pages/winpack/downloads
    here in this link i saw some samples regarding changing file types association
    , dont now will it works
    since this is for win32
    i found a program FileTypeAssociation dont know will it works
    * Copyright (c) 2002-2005 TeamDev Ltd. All rights reserved.
    * Use is subject to license terms.
    * The complete licence text can be found at
    * http://www.jniwrapper.com/pages/winpack/license
    package com.jniwrapper.win32.shell;
    import com.jniwrapper.Function;
    import com.jniwrapper.LongInt;
    import com.jniwrapper.Pointer;
    import com.jniwrapper.UInt;
    import com.jniwrapper.win32.registry.RegistryKey;
    import com.jniwrapper.win32.registry.RegistryKeyType;
    import com.jniwrapper.win32.registry.RegistryKeyValues;
    import com.jniwrapper.win32.registry.RegistryException;
    import java.io.File;
    * This class provides functionality for creating file type associations.
    * @author Vladimir Kondrashchenko
    public class FileTypeAssociation
    private static final String FUNCTION_SHCHANGENOTIFY = "SHChangeNotify";
    private static final long SHCNE_ASSOCCHANGED = 0x08000000L;
    private static final long SHCNF_IDLIST = 0x0000;
    private String _extention;
    * Creates a class instance for associating files of the specified type.
    * @param extention specifies the file type by its extention.
    public FileTypeAssociation(String extention)
    if (extention.startsWith("."))
    _extention = extention;
    else
    _extention = "." + extention;
    * Creates a file type association.
    * @param executable an associated file will be passed as a parameter of this executable file.
    * @param progID the programm identifier in the registry. If the specified prog ID is not exist, it
    * will be created.
    public void createAssociation(File executable, String progID)
    if (!executable.isFile())
    throw new IllegalArgumentException("File not found.");
    String commandLine = "\"" + executable.getAbsolutePath() + "\" \"%1\"";
    createAssociation(commandLine, progID);
    * Creates a file type association.
    * @param commandLine specifies an executable command.
    * @param progID the executable programm identifier in the registry. If the specified prog ID is not exist, it
    * will be created.
    public void createAssociation(String commandLine, String progID)
    RegistryKey registryKey = RegistryKey.CLASSES_ROOT.createSubKey(progID+"\\shell\\open\\command", true);
    RegistryKeyValues values = registryKey.values();
    if (commandLine != null)
    values.put("", commandLine);
    else
    values.put("", "");
    registryKey.close();
    registryKey = RegistryKey.CLASSES_ROOT.createSubKey(getExtention(), true);
    values = registryKey.values();
    values.put("", progID, RegistryKeyType.SZ);
    registryKey.close();
    changeNotify();
    * Removes all associations for the file extention.
    public void removeAssociation()
    try
    RegistryKey.CLASSES_ROOT.deleteSubKey(getExtention());
    catch(RegistryException e)
    try
    RegistryKey.CURRENT_USER.openSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts").
    deleteSubKey(getExtention());
    catch(RegistryException e)
    try
    RegistryKey.LOCAL_MACHINE.openSubKey("SOFTWARE\\Classes").deleteSubKey(getExtention());
    catch (RegistryException e)
    changeNotify();
    * Returns the default executable command for the file extention.
    * @return the default executable command for the file extention.
    public String getDefaultCommand()
    RegistryKey key = RegistryKey.CLASSES_ROOT.openSubKey(getProgID());
    key = key.openSubKey("\\shell\\open\\command");
    RegistryKeyValues values = key.values();
    return values.get("").toString();
    * Returns the program identified of the default executable program.
    * @return the program identified of the default executable program.
    public String getProgID()
    RegistryKeyValues values = RegistryKey.CLASSES_ROOT.openSubKey(getExtention()).values();
    return values.get("").toString();
    * Returns <code>true</code> if a file type association for the specified extention is registered.
    * @return <code>true</code> if a file type association for the specified extention is registered.
    public boolean isRegistered()
    try
    RegistryKey.CLASSES_ROOT.openSubKey(getExtention());
    catch (RegistryException e)
    return false;
    return true;
    * Returns the file extention.
    * @return the file extention.
    public String getExtention()
    return _extention;
    private void changeNotify()
    Function function = Shell32.getInstance().getFunction(FUNCTION_SHCHANGENOTIFY.toString());
    function.invoke(null,
    new LongInt(SHCNE_ASSOCCHANGED),
    new UInt(SHCNF_IDLIST),
    new Pointer(null, true),
    new Pointer(null, true));

  • Problem with creation of a jar file from inside a java program

    Hi,
    I am trying to create a jar file at runtime from within a java program.
    I am able to create a jar file just fine using:
    String[] jarArgs = new String[3];
    jarArgs[0] = "cvf";
    jarArgs[1] = "C:\temp\myjar.jar";
    jarArgs[2] = "C:\temp\this";
    sun.tools.jar.Main main1 = new sun.tools.jar.Main(System.out, System.err, "jar");
    main1.run(jarArgs);However, when I look at the jar it puts the absolute path to the files inside such as:
    C:\temp\this\is\my\package\Class.class
    instead of only this\is\my\package\Class.class
    When running the jar command from the command line it works just fine and I have the relative paths in my jar file.
    Does anyone have any experience with this and could help me out?
    Thanks in advance
    Edited by: mruf on Apr 11, 2008 1:51 AM

    Shouldn't jarArgs[2] = "-C C:\temp\this"

  • Add file to ZIP in Java program

    Hi all,
    I already found a lot of documentations of how to ZIP files in Java with the java.util.zip package, like: http://java.sun.com/developer/technicalArticles/Programming/compression/
    This algorithm works fine when you always want to create a fresh ZIP file where put your current files in.
    But I have the following problem: I already have a ZIP file with lots of files in it, and I want to add another file to this ZIP! Unfortunately I did not find any solution of how to do this in a java program - any ideas? Is it possible at all?
    Thanks for all answers
    nocomm

    Maybe this will help.
    http://home.mindspring.com/~thornton.rose/articles/ZipJar/part2.html
    At the bottom of this link is a algorithm for updating a file in a JAR that can be used for ZIP.
    It looks to me that the only way to add a new file to a ZIP is to:
    1) Create a Temporary ZIP
    2) Add new file to ZIP
    3) Open old Zip
    4) Read each ZIP Entry in turn and write to temporary ZIP
    5) If all goes well then deleted old ZIP and rename temporary ZIP to the correct filename
    You will have a ZIP with all the old files in and the new file.

  • Problems running bat file with calls to java programs (.jar)

    I created a bat file with calls to jar programs. In each line,
    I put a call to the programs with parameters, but bat only
    executes the first line and ends execution.
    All lines of my bat file must be executed.
    What should I do?
    Best Regards,
    Pedro Felipe
    [http://pedrofao.blogspot.com|http://pedrofao.blogspot.com]
    [http://viajantesmundo.blogspot.com/|http://viajantesmundo.blogspot.com/]

    user8730639 wrote:
    I realized that the problem isn`t my bat file. I made tests calling another jar files and then all the lines of the batch file were executed. So, the jar file called on my previous bat is finnishing the execution. I verified and the jar apps worked without error.
    I would like to know if exists any command in Java that can cause this effect (close a batch), to modify the open source code of the application.Not that I know of.
    Is prism a bat file?
    If you are invoking bat files from your bat file without using call that would explain it
    :: mymain.bat file
    :: call the first bat file
    call prism.bat arg1 arg2 arg3
    :: call the other bat file
    call prism.bat arg4 arg5 arg6
    ::

  • Downloading unix archive file (.Z extension) from java program

    Hi,
    I am trying to download unix archive files with .Z extension from java program. When I use
    BufferedReader zReader = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
    and then read line by line and write it to file, downloaded file can't be decompressed. I tried to open it with winZip which supports .Z files but I get the message : Cannot open file, it does not appear to be a valid archive.
    How can I download file correctly?
    Any help would be appreciated.

    Hi,
    I am trying to download unix archive files with .Z
    extension from java program. When I use
    BufferedReader zReader = new BufferedReader(new
    InputStreamReader(urlConn.getInputStream()));
    and then read line by line and write it to file,How are you writing the file? Since it is binary data you need to be careful about using Reader/Writers, which are meant for character data. Look at using classes from the InputStream/OutputStream hierarchy.
    - N

  • Getting the log files from client using java program

    hi
    this is lalita...and i am doing a project in networking.... i am new to socket programming....i have established the socket connection between the client and server...with this site members' help....now i have to get the log files of the client system from the server.... via the created socket....i need it by tomorrow...i.e apr 12th ....as i have to show it to my guide...
    i just need a core java program that will get the log information of the client from the server......
    Can anybody please help me in this regard..... it would be of great help to me and my group....
    Anxiously awaiting for the replies....
    Thanking you and regards...
    Lalita.

    Simple.
    Server is listening on a specific port for the connection from the clients.
    Connect the client with the server on the above mentioned port.
    Open the streams on both side for the connection and run in separate thread.
    Define a protocol for communication between client and server.
    e.g after connection with the server the server send a text message to the client (send log) now the client first should the log file name and size to the sever and then send the file. the server should save the file.
    then disconnect the client or want to get another file or for other tasks define the other commands

  • Need urgent help. Execution of .exe files by calling from java program

    This program can execute small .exe files which donot take inputs. But does not work for exe files that take input and just hangs. What could be the problem. If anyone helps me I would be very grateful.
    Server code :-
    import java.io.*;
    import java.net.*;
    public class Server1 {
         private Player[] players;
         private ServerSocket server;
         private ExecHelper exh;
         String command = null;
         String message = null;
         public Server1() {
              players = new Player[5];
              try {
                   server = new ServerSocket( 12345, 5 );
                   System.out.println("Server started...");
                   System.out.println("Waiting for request...");
              catch( IOException ioe ) {
                   ioe.printStackTrace();
                   System.exit( 1 );
         } //end Server constructor
         public void execute() {
              for( int i = 0; i < players.length; i++ )
              try {
                   players[i] = new Player( server.accept() );
                   players.start();
              catch( IOException ioe ) {
                   ioe.printStackTrace();
                   System.exit( 1 );
         public static void main( String args[] ) {
              Server1 ser = new Server1();
              ser.execute();
              System.exit( 1 );
         private class Player extends Thread {
              private Socket connection;
              private ObjectOutputStream output;
              private ObjectInputStream input;
              public Player( Socket socket ) {
                   connection = socket;
                   try {
                        input = new ObjectInputStream( connection.getInputStream());
                        output = new ObjectOutputStream( connection.getOutputStream());
                        output.flush();
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
                        System.exit( 1 );
              public void run() {
                   try {
                        message = "Enter a command:";
                        output.writeObject( message );
                        output.flush();
                        do {
                             command = ( String ) input.readObject();
                             String osName = System.getProperty( "os.name" );
                             String[] cmd = new String[3];
                             if( osName.equals( "Windows 2000" )) {
                                  cmd[0] = "cmd.exe";
                                  cmd[1] = "/c";
                                  cmd[2] = command;
                             else if( osName.equals( "Windows NT" ) ) {
                             cmd[0] = "cmd.exe" ;
                             cmd[1] = "/C" ;
                             cmd[2] = command ;
                             Runtime rt = Runtime.getRuntime();
                             Process proc = rt.exec( cmd );
                             exh = new ExecHelper( proc, output, input);
                        } while( !command.equals( "TERMINATE" ) );
                   catch( Throwable t ) {
                        t.printStackTrace();
         } //end class Player
         public class ExecHelper implements Runnable {
         private Process process;
         private InputStream pErrorStream;
         private InputStream pInputStream;
         private OutputStream pOutputStream;
         private InputStreamReader isr;
         private InputStreamReader esr;
         private PrintWriter outputWriter;
         private ObjectOutputStream out;
         private ObjectInputStream in;
         private BufferedReader inBuffer;
         private BufferedReader errBuffer;
         private Thread processThread;
         private Thread inReadThread;
         private Thread errReadThread;
         private Thread outWriteThread;
         public ExecHelper( Process p, ObjectOutputStream output, ObjectInputStream input ) {
              process = p;
              pErrorStream = process.getErrorStream();
              pInputStream = process.getInputStream();
              pOutputStream = process.getOutputStream();
              outputWriter = new PrintWriter( pOutputStream, true );
              in = input;
              out = output;
              processThread = new Thread( this );
              inReadThread = new Thread( this );
              errReadThread = new Thread( this );
              outWriteThread = new Thread( this );
              processThread.start();
              inReadThread.start();
              errReadThread.start();
              outWriteThread.start();
         public void processEnded( int exitValue ) {
              try {
                   Thread.sleep( 1000 );
              catch( InterruptedException ie ) {
                   ie.printStackTrace();
         public void processNewInput( String input ) {
              try {
                   out.writeObject( "\n" + input );
                   out.flush();
                   catch( IOException ioe ) {
                   ioe.printStackTrace();
         public void processNewError( String error ) {
              try {
                   out.writeObject( "\n" + error );
                   out.flush();
         catch( IOException ioe ) {
                   ioe.printStackTrace();
         public void println( String output ) {
              outputWriter.println( output + "\n" );
         public void run() {
              if( processThread == Thread.currentThread()) {
                   try {
                        processEnded( process.waitFor());
                   catch( InterruptedException ie ) {
                        ie.printStackTrace();
              else if( inReadThread == Thread.currentThread() ) {
                   try {
                        isr = new InputStreamReader( pInputStream );
                        inBuffer = new BufferedReader( isr );
                        String line = null;
                        while(( line = inBuffer.readLine()) != null ) {
                                  processNewInput( line );
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
              else if( outWriteThread == Thread.currentThread() ) {
                   try {
                        String nline = null;
                        nline = ( String ) in.readObject();
                        println( nline );
                   catch( ClassNotFoundException cnfe ) {
                   //     cnfe.printStackTrace();
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
              else if( errReadThread == Thread.currentThread() ) {
                   try {
                        esr = new InputStreamReader( pErrorStream );
                        errBuffer = new BufferedReader( esr );
                        String nline = null;
                        while(( nline = errBuffer.readLine()) != null ) {
                             processNewError( nline );
                   catch( IOException ioe ) {
                        ioe.printStackTrace();
    Client code :-
    // client.java
    import java.io.*;
    import java.net.*;
    public class Client {
         private ObjectOutputStream output;
         private ObjectInputStream input;
         private String chatServer;
         private String message = "";
         private Socket client;
         public Client( String host ) {
              chatServer = host;
         private void runClient() {
              try {
                   connectToServer();
                   getStreams();
                   processConnection();
              catch( EOFException eofe ) {
                   System.err.println( "Client terminated connection ");
              catch( IOException ioe ) {
                   ioe.printStackTrace();
              finally {
                   closeConnection();
         } //end method runClient
         private void connectToServer() throws IOException {                                                                 
              System.out.println( "Attempting connection...\n");
              client = new Socket( InetAddress.getByName( chatServer ), 12345);
              System.out.println( "Connected to : "+ client.getInetAddress().getHostName());
         private void getStreams() throws IOException {
              output = new ObjectOutputStream( client.getOutputStream());
              output.flush();
              input = new ObjectInputStream( client.getInputStream());
         private void processConnection() throws IOException {
         while( true ){
                   try {
                        message = ( String ) input.readObject();
                        System.out.print( message );
                        InputStreamReader isr = new InputStreamReader( System.in);
                        BufferedReader br = new BufferedReader( isr );
                        String line = null ;
                        line = br.readLine();
                             output.writeObject(line);
                             output.flush();
                   catch( ClassNotFoundException cnfe) {
                        System.out.println( "\nUnknown object type received");
         } //end processConnection
         private void closeConnection() {
              System.out.println( "\nClosing connection");
              try {
                   output.close();
                   input.close();
                   client.close();
              catch( IOException ioe ) {
                   ioe.printStackTrace();
         public static void main( String args[] ) {
              Client c;
              if( args.length == 0 )
                   c = new Client( "127.0.0.1" );
              else
                   c = new Client( args[0] );
              c.runClient();

    pay close attention to the comments in this thread
    http://forum.java.sun.com/thread.jspa?threadID=769142&messageID=4383764#4383764

  • Open a file in a running java program via double click

    I have already implemented opening my program with the corresponding file after a double click in windows explorer or from the cmd line but how do you open a file into the program if it is already running as MS Word will open a .doc file in the current word instance if you are running it.
    Thx,
    Jim

    Implement some sort of interprocess communication in your program. If you launch an instance, it can check whether another is running and pass a message to it telling it to perform the wished action.

  • How to use .dbf files zipped into a .zip file from within a java program

    i have a .zip file containing several .dbf files.
    the zip file is automatically downloaded regularly and data from the .dbf files is inserted into the database.
    how do i facilitate automatic extraction of a zip file or how do i fetch data from the .dbf file? (this cannot be done manually)
    anu.

    you could write a little polling class checking the zip file. you can use the java.util.jar package to extract the zip file (http://java.sun.com/docs/books/tutorial/jar/api/index.html). you could also use Jakarta ant (http://ant.apache.org/manual/index.html) to do this job (core task "zip") and call ant's target file on a regular basis (dependend on the OS you use, you can set os tasks/schedules).

  • Image file type supported by Java? PGM?

    Hello, does java support .pgm image format?
    If it does, how to know dimension size of the image using Java?
    Thank you

    By default, jpg, gif and png images are supported.
    you know the image size when loaded, withe the getWidth and getHeight methods.
    Other format could be supported by imageio API, but i'm not an expert.

Maybe you are looking for