How to launch a file in swing

i have a text file at following path . " C:\Documents and Settings\Administrator\My Documents\pavan.txt ". I want to open this text file in notppad . pls suggest swing api to achive this.

Your question is Windows centric, so here is a Windows only solution:
**  Here is a pure Windows solution
**  Run the code and you will be taken to a tutorial that may provide
**  a more generic solution
public class WindowsFileProtocolHandler
     public static void main(String[] args)
          throws Exception
          String[] cmd = new String[4];
          cmd[0] = "cmd.exe";
          cmd[1] = "/C";
          cmd[2] = "start";
          cmd[3] = "http://www.javaworld.com/javaworld/javatips/jw-javatip66.html";
//          cmd[3] = "will.xls";
//          cmd[3] = "mailto:";
//          cmd[3] = "a.html";
//          cmd[3] = "file:/c:/java/temp/a.html";
          Process process = Runtime.getRuntime().exec( cmd );
}

Similar Messages

  • Kindly help me how to view html file in swing using jbutton

    hello..im a begginer at j2se language and im working on my school project..kindly help me how to view html files by clicking button at javax.swing..thanks

    Here you go:public class HTMLViewer implements Runnable, ActionListener
         public void run() {
              JFrame frame = new JFrame("View HTML");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JButton button = new JButton("Click me!");
              button.addActionListener(this);
              Container cp = frame.getContentPane();
              cp.add(button, BorderLayout.CENTER);
              frame.pack();
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
         public void actionPerformed(ActionEvent e) {
              if (Desktop.isDesktopSupported()) {
                   Desktop d = Desktop.getDesktop();
                   try {
                        d.browse(new URI("www.google.com"));
                   } catch (IOException ex) {
                        ex.printStackTrace();
                   } catch (URISyntaxException ex) {
                        ex.printStackTrace();
         public static void main(String[] args) {
              EventQueue.invokeLater(new HTMLViewer());
    }If that's not what you're looking for you need to ask more specific questions.

  • How to launch local files in SIENA

    When I try to open a file (listed in the data source excel table and marked as hyperlink) from a network share in SIENA with a gallery link like this:
    launch("file:///\\server\share\document.pptx") the expected document open in Powerpoint on a splittscreen. When I try the same for a locale file launch("file:///c:\folder\document.pptx") or in this notation launch("file:///\\localhost\share\document.pptx")
    file couldnt open.
    Can anyone tell me how to solve this issue! I'm going crazy with this problem.
    Thanks!

    Hello,
    thanks for the answers! But thats not the answers that I want to hear ;-))
    Ok, will this function be implemented in one of the following Versions of SIENA? 
    And the other thougt is, local files are much more trustworthy then remote files. Wouldn't it make more sense when remote files  are blocked??
    Is there no way to tag the local Zone as Intranet / Internet Zone?
    Thanks for your help!!

  • How to launch java files on Mac OS

    Hey! I got a question: how to wrap a java file into Mac OS executable file? Analog for Windows is exe4j . It creates a jre in a exe file , so a person dont need to install runtime env. So any way to do like that? I need to launch program on Mac OS without terminal & installed jre. Just double-click on icon. Thanx for response.

    jwenting wrote:
    won't work. The question is how to execute a Java source file as a Mac executable.I don't think that's what the OP wants. To quote him:
    I need to launch program on Mac OS without terminal & installed jre. Just double-click on icon.Sounds exactly as if he'd like to have an executable jar file. And since Mac OS X comes with a JRE preinstalled, there is no more magic necessary to make it easily usable.

  • How to embed html-file into swing

    hello,
    can anybody help me how to embed a html-file into a swing application??
    I try to write a swing-application, that connects to a Internetpage via Sockets.
    The problem is, that I can only see the sourcecode of the InternetPage in my JTextArea, but I want to see the whole Page just like in a browser.
    I hope anybody can help me to solve this problem, thanx mina

    u will need to use the JEditorPane component instead of Jtextarea.here is a url to help u get started
    http://java.sun.com/docs/books/tutorial/uiswing/components/simpletext.html#editorpane

  • How to launch Jar file in Mac Os using java code??

    can anyone tell me how can i launch another jar file in my apllication using java code.

    define "launch".
    - You want to run a new java program in a separate process? (see Runtime.exec())
    - You want to run a method in a specific class in the jar? (add jar to application classpath and then simply instantiate the class and call the method)

  • How to create html files using Swing

    I am developing a billing system in java. I want to generate cash memo and other related documents in HTML format. I have explored html package in swing but without result. Please help me.
    Arshad

    Hi,
    I agree with the previous poster. An additional way of generating HTML would be to directly write it. Class SHTMLWriter in package com.lightdev.app.shtm of application SimplyHTML at http://www.lightdev.com/template.php4?id=3 gives this opportunity.
    With this, you can do something such as   /**
       * example of synthesizing HTML code to a Writer using
       * class SHTMLWriter
       * @param fileName the name of the file to write HTML to
      public void writeHTML(String fileName) {
        try {
          FileWriter fw = new FileWriter(fileName);
          SHTMLWriter w = new SHTMLWriter(fw);
          w.startTag(HTML.Tag.HTML.toString(), null);
          w.startTag(HTML.Tag.BODY.toString(), null);
          SimpleAttributeSet set = new SimpleAttributeSet();
          set.addAttribute(CSS.Attribute.FONT_FAMILY, "SansSerif");
          set.addAttribute(CSS.Attribute.FONT_SIZE, "12");
          w.startTag(HTML.Tag.P.toString(), set);
          fw.write("some text");
          w.endTag(HTML.Tag.P.toString());
          w.endTag(HTML.Tag.BODY.toString());
          w.endTag(HTML.Tag.HTML.toString());
        catch(Exception e) {
          e.printStackTrace();
      }The HTML output is hard coded in this example. Certainly any HTML code can be created dynamically/programmatically instead. Class SHTMLWriter is partly meant as a convenience class for writing HTML. One can just through start and end tags as in above example. In the start tag any valid AttributeSet can be given.
    HTH
    Ulrich

  • How to display text file in  swing

    hello,
    I have screen where user enters batch number and number.
    when key is pressed a list is displayed on the screen.how to do this and how to relate my actionlistener with the function that generates the list...

    Hi,
    It is simple. Just create a button and add it to the action listener as button.addActionListener(this);
    Your class should extend ActionListener. and also there should be a method named - actionPerformed(ActionEvent avt) in your class
    Now inside this method, just compare the action as:
    if(avt.getSource()==button)
    // in this method, hjust take your file contents and display it on the same window, or create a new Frame here and display it in that window.
    If you want to display the file contents in the same window, then do the following.
    Declare a public JLabel variable for the class and create the JLabel along with the other components as usual but without giving any values. Now in the action part of the button, read the file contents in a string variable, and set the string to the jlabel as folows:
    label.setText(string);
    Hope it helps,
    Cochu.

  • How to launch code file.exe java

    As I directly serve to launch a lines executable situated in a directory as the code java

    Launching exe files is, of course, OS specific.
    // Windows:
    String command = "cmd /c start calc.exe";
    Runtime.getRuntime().exec(command);Details:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html

  • How to launch sw file in default fullscreen mode

    Hi,
    I want to execute .swf or output flash file in fullscreen mode. Is there any property for it?

    Hi Swati,
    You can try following code snippet:
    <mx:Application width="{Capabilities.screenResolutionX}" height="{Capabilities.screenResolutionY}" />
    or
    on creationComplete event
    public function onCreationComplete():void
         this.width = Capabilities.screenResolutionX;
         this.height = Capabilities.screenResolutionY;
    Thanks.

  • Launching .desktop files

    Noob here running arch with i3 and dmenu and I can't figure out how to launch .desktop files. If I open /usr/share/applications in a filebrowser, doubleclicking a .desktop file opens it up in my editor. If I add /usr/share/applications to my $PATH they show up in dmenu but again open up with my editor. Same goes for xdg-open file.desktop which corresponds with this bug.
    #!/usr/bin/env xdg-open
    [Desktop Entry]
    Version=1.0
    Name=Test
    Exec=chromium --app=http://localhost:8080/
    Terminal=false
    Icon=chrome-http___localhost_8080__1
    Type=Application
    Categories=GTK;Network;WebBrowser;
    StartupWMClass=localhost

    Is that part of xfce? I can't figure out how to install that on its own. I'd rather not a desktop environment just to get this working.

  • Launch Batch files from Windows.

    Hello,
    I'm currently trying to launch a batch file from a Java class.
    I succedeed to launch one .exe file but the same code does not work with my .bat files :
    Runtime r = Runtime.getRuntime();
    Process p = null;
    try
    p = r.exec("d:/EASTv2/bin/ihm_duw.bat");
    catch( java.io.IOException e )
    e.printStackTrace();
    I'm working under Windows 2000.
    Can anyone tell me how to launch batch files from a java class ?
    Thanks in advance,
    J�r�me.

    try this
    r.exec("cmd.exe /C d:/EASTv2/bin/ihm_duw.bat");

  • Launching SWF file within the project - Video Avatar and Calculator

    Hi There, I am somewhat new to Captivate so please bear with me. I am using Captivate 6.0 and have basic coding knowledge. I have a question about how to launch SWF files within my project. There are 2 things I am trying to accomplish.
    1. I have a video avatar that I want to use within my project. When a user clicks an icon or button on certain screens I want the appropriate video to launch within the same window. My video is an swf file but it can be another file type if that is better. Is this something that I can accomplish with Captivate 6.0?
    2. I have built a basic flash calculator - also an swf file - that I want the user to be able to launch on certain screens. When the user clicks a calculator button, the calculator would launch for the user to use, then the user would be able to close the calculator and return to the screen they were on.
    Could someone direct me to some resources on how to accomplish this? If there are any widgets that would make this easier that would be great - but if I need to write some code I can try and do this if someone can direct down the right road. I have spent hours looking for information on this topic but can't find any (at least any that I understand)
    Please, and thank you!!!

    Rory,
    Your Video is 720 x 480 @ 1.212 PAR, according to your screen-cap. In Photoshop (PS), go to Image New (Ctrl+N) and choose the NTSC 720 x 480 Widescreen 16:9 PAR 1.2. Once done, choose Image>PAR and Custiom, change 1.2 to 1.212 (this was a change in PrPro, and might not have yet made it into PS yet). Now, Open your full rez image. Ctrl+A (Select All), Ctrl+C (Copy), and then bring focus to your New Image. Hold Shift and Ctrl+V (Paste). This will put your image on a New Layer, Layer 1, in an Image with the correct dimensions and PAR. You can the Ctrl+T (Free Transform) and adjust the size of your Layer 1 image to suit. Holding down Shift while dragging the Handles of the Bounding Box will constrain the Aspect Ratio. Note, you might be cropping some of that image to fit the Aspect Ratio of your New Image. Anything outside of the Image boundries will effectly be cropped off. Note: you are NOT using the Crop Tool here, but letting the New Image Aspect Ratio effectively do the cropping (note no capitalization) for you. When satisfied with the result, you Delete the Background Layer (not necessary, but I do this to clean things up a bit), and Save_As .PSD to the proper folder.
    With Scale to Fit turned OFF, Import_As Footage, this image and drag to the Timeline, making sure that Scale to Fit is OFF. It should be perfect then. Hope that this works for you and gets rid of the problem.
    Good luck,
    Hunt

  • How to print a PDF file from Swing(JFC/swing)

    Hi,
    I am able to dislay a PDF file in Swing but how can I print it from there. I want to do it without using Acrobat reader.

    You can use the "System Exec.vi". The command line should have the following structure:
    "<Path to AcroRd32.exe>" /t "<Path to document>" "Printer name"
    For example"
    "C:\Program Files\Adobe\Acrobat 5.0\Reader\AcroRd32.exe" /t "C:\myreport.pdf" "Tektronix Phaser 300i"
    Regards;
    Enrique
    www.vartortech.com

  • How to embed and launch ipa file from another ipa package created using Air for iOS

    Hi Guys,
    Anybody out there knowing how to embed and launch ipa file from another ipa package created using Air for iOS ?
    I am having 1 ipa file created using Xcode, Now i need to include that file in my ipa Package which is created using Flash CS 5.5 and Air for iOS. Also i need to know how to open my 1st ipa file from AS3 ?
    Thanks,

    Hi Sir,
    Thanks for your reply.
    But in that case user need to download 2 applications right. I need user to download my parent application created using Flash and that package contain one more ipa created using Xcode, so from my parent app only user should able to open my 2nd app. Is there any way to do that?
    Ps:  I am not talking about in-app but 2 individual apps inside one package.

Maybe you are looking for

  • [SUCCESS] Can I upgrade my harddrive in my HP laptop?

    I am considering upgrading the harddrive in my laptop. Right now I have a 160GB drive, and I feel a little closed in with so little space. The laptop needs to run both win and linux, so I dual boot. that doesn't really make the situation any better,

  • How to stop ipod classic from loading in compatibal mode from an older version of Microsoft

    Error message upon opening my iTunes iTunes.exe has ben set to run in compatibility mode for an older version of Windows. For best results, turn off campatibility mode for iTunes before you open it. HOW IS THIS DONE??? NEED sone guidence. Thank you f

  • Itunes (WinXP) Crashes OS when importing CD

    Hi all, My Sister is having a problem importing CDs into iTunes. She has tried importing the Mary J Blige The Essential collection and also the Killers Sams Town recently and its blue screened her laptop and then restarts. It manages to import around

  • Payment made not able to call

     My subscription had auto renewed and the order was delivered on 24th July . My account settings said that i can have the free minutes from 26th July .I have not no free minutes yet . Kindly help

  • How to covert JPEG files (OS 8-9) that show as Text Docs

    I have some old 3.5 mini floppy (1.44mb) disks that I managed to save picture data on (JPEG) but the files show as Text Documents. I have an old PB G4 17" with Tiger and classic (OS 9.1.x) but cannot figure out how or what to use to convert these fil