Opening a  File in Java

The name of Ms-Exel file is stored in Ms-Access Database.
Ms-Access Database . Report.dat
There two Columns
Rep_Name = which will have the Report Name
Rep_Excel = Which will have Excel File name
i will be creating a GUI whereby I will access the database and display the report names.
Depending on what the user selects I woukd l like to make a call to Excel and Open that respected file for that Rep_Name.
The File I am opening in Excel will be taken from the MS-ACCESS DATABASE.
After the report is displayed , on clicking the close button there should be option to come back to the java program

1. retieve th efilename from th edatabase.
2. open the excel file
for #2, if you want tyo open it within your Java application (so your Java application have access to the file..like to modify and update the Excel file)..then you will ned some sort of Excel API, like Jakarta POI as suggested. If you just want to open the excel file using MS Excel application (your Java application will not be able to do anything - like modify the Open Excel file) , then you can use Runtime class and its exec() method to launch the Excel application.

Similar Messages

  • How to open/read file using Java in Unix?

    Hi Friends,
    Can you please help me out how to open/read file using java in unix os? I have create one text file in "/home/test.txt" in unix environment. How to open the same file & read using java code?
    - Hiren Modi

    http://java.sun.com/docs/books/tutorial/essential/io/index.html

  • Open a file using java......... how?

    hi all
    I have a prob with my code
    the problem is by using the FileChooser like
    file = fileChooser.getSelectedFile();
    I have the file name but how can i open that file e.g. if file is word document then that file should open in word , if that file is HTML file then open in IE , and other files as well.
    is there any way to open a file
    plz help me
    Thanx
    Regards
    Satinderjit

    veer ji, try this code on your pc if you can. Click the print button and see that happens. thanx yuvraj:
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    //import com.sun.java.swing.*;
    import javax.swing.*;
    public class ComponentPrinterFrame
    extends JFrame
    implements Printable {
    public static void main(String[] args) {
    ComponentPrinterFrame cpf = new ComponentPrinterFrame();
    cpf.setVisible(true);
    public ComponentPrinterFrame() {
    super("ComponentPrinterFrame v1.0");
    createUI();
    protected void createUI() {
    JPanel panel = new JPanel();
    JButton printButton = new JButton("Print");
    panel.add(printButton);
    panel.add(new JList(new Object[] { "One", "Two", "Three" }));
    panel.add(new JButton("Push me"));
    panel.add(new JCheckBox("Chess", true));
    panel.add(new JComboBox(new Object[] { "Eins", "Zwei", "Drei" }));
    printButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    PrinterJob pj = PrinterJob.getPrinterJob();
    pj.setPrintable(ComponentPrinterFrame.this);
    if (pj.printDialog()) {
    try { pj.print(); }
    catch (PrinterException pe) {
    System.out.println(pe);
    setContentPane(panel);
    setSize(400, 400);
    // Center.
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = getSize();
    int x = (screenSize.width - frameSize.width) / 2;
    int y = (screenSize.height - frameSize.height) / 2;
    setLocation(x, y);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    dispose();
    System.exit(0);
    public int print(Graphics g, PageFormat pf, int pageIndex) {
    if (pageIndex != 0) return NO_SUCH_PAGE;
    Graphics2D g2 = (Graphics2D)g;
    g2.translate(pf.getImageableX(), pf.getImageableY());
    getContentPane().paint(g2);
    return PAGE_EXISTS;

  • Open .doc file in java on Windows 98/2000

    Hi all,
    I need to open a .doc file on Windows 98/2000 PC thriugh java.I have used the command
    Runtime.getRuntime().exec(new String[] {"cmd", "/C", "start", "\"\"", filename});
    This command works fine on Window 2000 but gives IO Exception: CreateProcess: start <filename> error=2
    So I tried the command
    Runtime.getRuntime().exec("start"+filename);
    Now this command works fine on Windows 98 but gives the same error on Win2000.
    Someone please suggest a command which will work fine on all Windows OS.
    Thanks in advance

    Have a look at the Java Desktop Integration Components Project https://jdic.dev.java.net/documentation/index.html
    especially look at
    https://jdic.dev.java.net/nonav/documentation/javadoc/jdic/org/jdesktop/jdic/desktop/Desktop.html#open(java.io.File)
    which opens a File using the default application associated with this kind of file.

  • How to Open a file by JAVA SCRIPT in ABAP?

    Hi Experts,
    i'm trying to open a pdf file in java script (ONLY) through ABAP.
    Is it possible? If so how?
    The java script what we write in HTML is "window.open("C:
    Temp
    file.pdf");"
    Please advice ASAP.
    Somnath

    Hi,
    You have to make the Vi reentrant so that it does not share the same memory location:
    Regards,
    Even
    Certified LabVIEW Associate Developer
    Automated Test Developer
    Topro AS
    Norway

  • Opening .doc files from Java

    Ok, here's my problem.
    I'm using Java to create an autorun program for a little thing I'm putting together.
    One of the options should be "Read documentation" . However, to do that, I need to make my program open a Microsoft Word (.doc) document. What is the command/how can I do this? By open, I mean open the file in MS Word for viewing.

    When you say "where filename is the path" do you mean
    type in "\documentation\file.doc" or is it a variable?It's a variable in the example. It doesn't matter -- just as long as the resulting string passed to exec will contain the correct file name so the OS will see it.

  • Open servlet file from java

    can i open servlet file from java

    do you mean linking to a servlet from java application?
    have you try this?
    URL toServlet = new URL("URLtoServlet");
    URLConnection servletConnection = toServlet.openConnection();

  • Opening image files in java applet

    Hi,
    I made an applet that opens up the image file and displays it.
    When the photo is loaded, the program sets boolean photoLoaded = true;
    and when the image is loaded, it has to do something else.
    the problem is that I have to open the file twice meaning I would click
    "open" button and select the photo, which doesn't do anything, so I have to go back
    and click open button, select the photo, and open up again.
    When I changed the code slightly so that it shows the first time, photoLoaded is still false the first time,
    so I still have to open it up twice for photoLoaded to be true.
    methods for opening an image file:
        private void loadPhoto() throws Exception{
            Frame parent = new Frame();
            FileDialog fd = new FileDialog(parent, "Please choose a image file:",
                FileDialog.LOAD);
            fd.show();
            String selectedImage = fd.getFile();
            if(selectedImage == null){
                // no image file selected
            }else{
                File ffile = new File(fd.getDirectory() + File.separator +
                                    fd.getFile());
                boolean canOpen = accept(ffile);
                if(canOpen){
                    imageLoaded = kit.getImage(selectedImage);
                    width = imageLoaded.getWidth(ob);
                    height = imageLoaded.getHeight(ob);
                    /*get image*/
                    imageLoaded = getImage(getCodeBase(), selectedImage);
                    tracker.addImage(imageLoaded, 0);
                    /* wait until image is loaded */
                    try{
                        tracker.waitForAll();
                        photoLoaded = true;
                    }catch(InterruptedException ex) {
                        //does nothing
                    repaint();
        public boolean accept(File f){
            if(f.isDirectory()){
                return true;
            String extension = Utils.getExtension(f);
            if(extension !=null){
                if(extension.equals(Utils.gif) ||
                   extension.equals(Utils.jpeg) ||
                   extension.equals(Utils.jpg)){
                       return true;
                } else{
                    return false;
            return false;
        public static class Utils{
            public final static String jpeg = "jpeg";
            public final static String jpg = "jpg";
            public final static String gif = "gif";
            /* get the extension of a file */
            public static 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;
        }and the paint method:
        public void paint(Graphics g)
            g.drawImage(background, 0, 0, this);
            if(photoLoaded == true){
                g.drawImage(imageLoaded, startingPtX, startingPtY, ob);
        }does anybody have idea on what's wrong with it?
    thanks!

    Is this what you mean by you have to load it twice? You load the image, then add it to the MediaTracker, then you do what ever you want with it--like get the width and height and set you flags.
       imageLoaded = kit.getImage(selectedImage);
       width = imageLoaded.getWidth(ob);
       height = imageLoaded.getHeight(ob);
       /*get image*/
       imageLoaded = getImage(getCodeBase(), selectedImage);
       tracker.addImage(imageLoaded, 0);

  • How can we open any file using JAVA...

    Hi all
    i trying to make code in that code i choose a file using a filechooser then put that file name in FILE object like (File file = fileChooser.getSelectedFile();)
    but the thing is how can i open that file for example if that file is HTML file then opens in IE or if that file is MS Word document that open in Word, like that
    is there any suggestions
    Thanx
    Regards
    Satinderjit

    start is a windows command-line utility.
    start foo.doc will start Word (or Star Office or Word Perfect or whatever is registered for the .doc extension),
    start bar.htmnl will start your registered browser etc.

  • Error trying to open a file using java.io.* in an Applet

    I have a file called wordlist.txt and I am using java.io.* to open it. When I try it
    in Applet Viewer it runs without a hitch. But when I try to run it in a
    browser as an Applet, it errors out saying:
    com.ms.security.SecurityExceptionEx[package3/SpellCheck.setWordList]: cannot access file wordlist.txt
    I have tried adding this file to my Project and accessing it that way but I still get
    the same message. If anyone can help with this, I sure would appreciate it.
    My code is as follows:
    String inWord = new String("zzz");
    try {
    File myWordList = new File("wordlist.txt");
    BufferedReader inWordList = new BufferedReader(
    new FileReader(myWordList));
    inWord = inWordList.readLine();
    while (inWord != null) {
    wordList.addElement(inWord);
    inWord = inWordList.readLine();
    } // end while
    inWordList.close();
    } // end try
    catch (Exception e1) {
    // Pr is equivalent System.out.println();
    Pr("Error Reading this line " + '\n' + inWord + '\n' + e1);
    } // end catch
    } // end setWordList()

    Applets are generally prevented from reading as well as writing files, but appletviewer can load files from the hard drive, so, that is the cause of the behaviour you have observed. To know more about enabling applets load files, you have to sign your applets,
    learn more at
    http://java.sun.com/sfaq/#prevent

  • Open  a file using Java

    Write a java program to open a text file. Check if the file already exists. If the file already exists then append data to it. Otherwise program should write 10 lines of text data in the file.

    i was told that all i need to do is
    BufferedReader in = new BufferedReader(new FileReader(filename));
    in.readLine()
    then just write to it
    but i am not sure on how to do that.
    If anyony can help me i would appreciate it..
    thanks

  • Linking to Open a file in java

    Hello,
    I wanted to create a link in my program that opens an excel spread sheet, seperately from the program. (i.e opens in excel). Is it possible to do this?
    Thanks
    Stu
    Message was edited by:
    studomonly

    import java.io.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    class OpenExcelDemo {
        public static void main(String[] args) {
            new OpenExcelDemo().go();
        void go() {
            JFileChooser jfc = new JFileChooser();
            FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel Files", "xls", "csv");
            jfc.setFileFilter(filter);
            int returnVal = jfc.showOpenDialog(null);
            if(returnVal == JFileChooser.APPROVE_OPTION) {
               open(jfc.getSelectedFile());
        private void open(File f) {
            String[] commands = {
                "rundll32",
                "url.dll,FileProtocolHandler",
                f.getAbsolutePath()
            try {
                Runtime.getRuntime().exec(commands);
            } catch (IOException e) {
                e.printStackTrace();
    }All normal caveats apply.
    ~

  • Opening HTML file from java GUI

    Can someone please tell me how I can open a HTML file in Internet Explorer from a Java GUI,
    I have an asssignment I am doing for college and I was toying with the idea of putting in helpfiles, for the program, can anyone tell me the easiest way of apcomplishing this???
    Thanks in advance for your help,
    Kaspah

    Although this should answer your question, there are other (cross platform) ways to do what you want. As opposed to your "must have internet explorer" solution. Swing has a built in html viewer you might use, for example. I've been doing some reading on java/xml solutions. I don't consider myself knowledgeable enough (yet) to comment on that solution though. A delimited text file would be another solution. Useing that solution you could treat the file like a set of parrallel arrays on the hard drive and disply your text on pre-formated labels. Anyway, here is a link to you answer......
    http://java.sun.com/products/jdk/1.2/docs/api/java/lang/Runtime.html#exec(java.lang.String)
    Ron_W

  • Webb Exception - java.util.zip.ZipException: error in opening zip file

              I am tring to run my Servlet with myWAR.war. So I started first installing the CookieCounter example that came with weblogic, I did exactly as the document said but I getting the following exception:
              Thu Jan 04 11:26:45 MST 2001:<E> <HTTP> Error reading Web application '/weblogic/myserver/cookieWar.war'
              java.util.zip.ZipException: error in opening zip file
              at java.util.zip.ZipFile.open(Native Method)
              at java.util.zip.ZipFile.<init>(ZipFile.java:69)
              at weblogic.utils.jar.JarFile.<init>(JarFile.java:57)
              at weblogic.utils.jar.JarFile.<init>(JarFile.java:44)
              at weblogic.t3.srvr.HttpServer.loadWARContext(HttpServer.java:582)
              at weblogic.t3.srvr.HttpServer.initServletContexts(HttpServer.java, Compiled Code)
              at weblogic.t3.srvr.HttpServer.start(HttpServer.java:388)
              at weblogic.t3.srvr.T3Srvr.start(T3Srvr.java, Compiled Code)
              at weblogic.t3.srvr.T3Srvr.main(T3Srvr.java:827)
              at java.lang.reflect.Method.invoke(Native Method)
              at weblogic.Server.startServerDynamically(Server.java:99)
              at weblogic.Server.main(Server.java:65)
              at weblogic.Server.main(Server.java:55)
              at weblogic.NTServiceHelper.run(NTServiceHelper.java:19)
              at java.lang.Thread.run(Thread.java:479)
              Has anybody encountered the problem before I created the jar using jar cvf cookieWar.war cookie- under the command line
              

    I have seen problems like this in the past. When you create your war file, try using "jar
              cv0f" so that the jar file won't be compressed...
              mark bouchard wrote:
              > I am having this same error... the strange thing is i have two different ear files...
              > one of them works, the other doesn't. there are NO differences between them according
              > to Araxis Merge... both will deploy, and both show servlets as being registered,
              > but i can only call the servlets from one...
              >
              > what is BEA's suggested way of creating an ear file? on NT and on UNIX please....
              >
              > use the java.util.zip methods? or use a utility like jar or winzip? Personally,
              > i've found this deployment to be HIGHLY flakey at best.... my same ear files
              > deploy perfectly with iPlanet's app server.
              >
              > Mark Spotswood <[email protected]> wrote:
              > >I think this is basically the same as a file not found error.
              > >The error message says it can't open the file. Its looking
              > >for the file under: /weblogic/myserver/cookieWar.war
              > >Make sure the file is in that directory/readable, etc.
              > >--
              > >mark
              > >
              > >Paul Garduno wrote:
              > >
              > >> Just to let you know, I am getting the same error message. I haven't
              > >worked on it but hope to at some point. I would like to know if the
              > >Weblogic people have seen this error.
              > >>
              > >> Paul Garduno
              > >>
              > >> bionic99 wrote:
              > >>
              > >> > I am tring to run my Servlet with myWAR.war. So I started first installing
              > >the CookieCounter example that came with weblogic, I did exactly as
              > >the document said but I getting the following exception:
              > >> > Thu Jan 04 11:26:45 MST 2001:<E> <HTTP> Error reading Web application
              > >'/weblogic/myserver/cookieWar.war'
              > >> > java.util.zip.ZipException: error in opening zip file
              > >> > at java.util.zip.ZipFile.open(Native Method)
              > >> > at java.util.zip.ZipFile.<init>(ZipFile.java:69)
              > >> > at weblogic.utils.jar.JarFile.<init>(JarFile.java:57)
              > >> > at weblogic.utils.jar.JarFile.<init>(JarFile.java:44)
              > >> > at weblogic.t3.srvr.HttpServer.loadWARContext(HttpServer.java:582)
              > >> > at weblogic.t3.srvr.HttpServer.initServletContexts(HttpServer.java,
              > >Compiled Code)
              > >> > at weblogic.t3.srvr.HttpServer.start(HttpServer.java:388)
              > >> > at weblogic.t3.srvr.T3Srvr.start(T3Srvr.java, Compiled Code)
              > >> > at weblogic.t3.srvr.T3Srvr.main(T3Srvr.java:827)
              > >> > at java.lang.reflect.Method.invoke(Native Method)
              > >> > at weblogic.Server.startServerDynamically(Server.java:99)
              > >> > at weblogic.Server.main(Server.java:65)
              > >> > at weblogic.Server.main(Server.java:55)
              > >> > at weblogic.NTServiceHelper.run(NTServiceHelper.java:19)
              > >> > at java.lang.Thread.run(Thread.java:479)
              > >> >
              > >> > Has anybody encountered the problem before I created the jar using
              > >jar cvf cookieWar.war cookie- under the command line
              > >
              

  • WHY? java.util.zip.ZipException: error in opening zip file

    i'm trying to restart tomcat 4.1 (bin/startup.bat) and getting the following error (windows xp profession machine)
    code:
    java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:112)
    at java.util.jar.JarFile.<init>(JarFile.java:127)
    at java.util.jar.JarFile.<init>(JarFile.java:65)
    at org.apache.catalina.loader.StandardClassLoader.addRepositoryInternal(StandardClassLoader.java:1082)
    at org.apache.catalina.loader.StandardClassLoader.<init>(StandardClassLoader.java:200)
    at org.apache.catalina.startup.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:202)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:140)
    Bootstrap: Class loader creation threw exception
    java.lang.IllegalArgumentException: addRepositoryInternal: java.util.zip.ZipException: error in opening zip file
         at org.apache.catalina.loader.StandardClassLoader.addRepositoryInternal(StandardClassLoader.java:1110)
         at org.apache.catalina.loader.StandardClassLoader.<init>(StandardClassLoader.java:200)
         at org.apache.catalina.startup.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:202)
         at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:140)
    thanks!

    These exceptions occur when opening JAR files (since they are renamed ZIPs). Most likely the file cannot be ffound because you have classpaths setup incorrectly

Maybe you are looking for

  • How can I edit a PDF that auto fills on my Mac?

    I am trying to fill out PDF forms that will auto generate once I put in some numbers. The Preview does not let me do this on my Mac. Is there any way to do this without buying a super expensive app? I recently bought my Mac and I like it, but I am ha

  • What is the difference if jsp code in head section or outside of HTML

    I am confused about what is the difference if I include jsp code inside <html><head> jsp code </head><html>, or outside of HTML tag? What is the difference if I put the jsp code inside head senction or in the body section? Thank you in advance!

  • Path to Executable from Dynamicall​y called VIs

    QUESTION: How can I retrieve the path to an executable that is called from a VI that was created by dynamically loading a VI template? The application is a bit too complicated to post, so I will try to describe... I have a built executable. It dynami

  • How to define maximum field width on an updatable report

    I have an updatable report. From a user's perspective, this is a form in my app. How can I define the maximum number of characters the user can enter into a field? I tried entering the following into the report column's element attributes, but none o

  • Satellite A300 and Windows 7 - missing "Create a disk" option

    Hi. I installed windows 7 professional in my laptop A300 - 15C (PSAJ4E) two weeks ago and i have a problem. I Installed all drivers for win 7 from the official site of toshiba and i can't see the option of "Create a disk" where i can install the firm