How to open a file in java using JFileChooser

Ads
 

How to open a file in java using JFileChooser

How to open a file in java using JFileChooser

View Answers

March 14, 2011 at 11:47 AM

import java.io.*;
import javax.swing.*;
class OpenFileUsingJFileChooser{
    public static void main(String[] args)throws Exception{
        JFileChooser chooser=new  JFileChooser();
        int returnVal = chooser.showOpenDialog(null);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
        File f = chooser.getSelectedFile();
        BufferedReader br=new BufferedReader(new FileReader(f));
        String st="";
        while((st=br.readLine())!=null){
            System.out.println(st);
        }
      }
    }
}

March 31, 2012 at 9:34 PM

I just tried to use this portion of code and it just reprints the string that was entered in my file to the command prompt. I cannot figure out how to change it to actually open the file I select rather than printing it's contents back to the console.

Ads









Related Tutorials/Questions & Answers:
How to open a file in java using JFileChooser
How to open a file in java using JFileChooser  How to open a file in java using JFileChooser
wait until a file is opened using JFileChooser
wait until a file is opened using JFileChooser   I created a java... JFileChooser to open a file. b. call a funtion that takes in the filename as argument...); JButton b=new JButton("Open File"); b.addActionListener(new
Advertisements
how to open notepad using java
how to open notepad using java  Hi, how to open notepad using java? I want to open windows notepad from java program. Thanks   Hi, Use following code: import java.util.*; import java.io.*; class Notepad { public
How to transfer a file in java using SSH & Telnet
How to transfer a file in java using SSH & Telnet  How to transfer a file in java using SSH & Telnet
how to create an excel file using java
how to create an excel file using java  how to create an excel file using java
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar  How to create pdf file having paragraphs and alignments done using java and itextjar 5.10 version.? hope i get quick response
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
how to upload file using FTP in java
how to upload file using FTP in java  hai, i want to upload file using FTP in java Webservices.. Tel me some Articles Regards Asha
How to Split a large XML file using java?
How to Split a large XML file using java?  How can we split a 500MB Xml file?I know how to split xml file after reading the entire document in a file.Here we cannot load the entire file as it is a large file
How to link a excel file with a application software using java swing
How to link a excel file with a application software using java swing  I have to link an excel file with a application software which I am... is only able to open a Jpanel to select the file.After I select the file nothing
How to link a excel file with a application software using java swing
How to link a excel file with a application software using java swing  I have to link an excel file with a application software which I am... is only able to open a Jpanel to select the file.After I select the file nothing
How to link an excel file with the application software using java swing
How to link an excel file with the application software using java swing  I have to link an excel file with a application software which I am... is only able to open a Jpanel to select the file.After I select the file
how to read file using InputStreamReader in java
how to read file using InputStreamReader in java  Hi, I want to learn to use the InputStreamReader class of Java and trying to read a text file with the class. how to read file using InputStreamReader in java? Thanks  
how to convert war file into .exe file using java code
how to convert war file into .exe file using java code  hi,I am beginner in the java,I want to convert my java maven project to .exe file,plz tell me which is required jar files and how i convert this..?Thanks in advance
how to open java
how to open Java  how to open java file simple Java Example
how to use Excel Templet to write excel file using java.
how to use Excel Templet to write excel file using java.  how to use Excel Templet to write excel file using java
How to download and save a file from Internet using Java?
How to download and save a file from Internet using Java?  How to download and save a file from Internet using Java
how to use Excel Template to write excel file using java
how to use Excel Template to write excel file using java  How to use Excel template to write data in that file using java
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java    How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java   reading the data from Html file
how to open a file of .110 extension??
how to open a file of .110 extension??  I have a file which is in .110 extension and that file is belongs to Nokia 1100 mobile. How to open that kind of file format? Do i need any converter to open that? So that i can understand
how to convert doc file into html using java swing
how to convert doc file into html using java swing  i want to convert doc file into html and display it on jtextarea please help me and give the sample code
How to Open a File in HTML Form
How to Open a File in HTML Form  Hi, My question in that how could i open a file in HTML Form. Could any one suggest me the examples or online help... it. Otherwise take this examples and syntax that will show how to Open a file in HTML
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... and custructor. To open some file we require it to be open in append mode by using... bufferedWriter object to write in the file. For more details and examples related to How
sir, how to convert excel file to csv file using java? please send me sample code.
sir, how to convert excel file to csv file using java? please send me sample code.  please send me sample code for converting excel file into csv file uisng java
how to read file line by line using filereader in java
how to read file line by line using filereader in java  Hi, how to read file line by line using filereader in java? Thanks   Hi, This is example code: package my.code; import java.io.BufferedReader; import
How to attach file to HP Quality Center [QC] using java
How to attach file to HP Quality Center [QC] using java  Hello All, Do any one know how to upload attachments to QC Test Case Run Instance using java In QC we have <BR> Test Lab<BR> |_Test Set Instcance<
How to select only .txt file to be zipped using java?
How to select only .txt file to be zipped using java?  Hello, i'm trying to zipp .txt files from a folder but i want to know how to select only .txt file. I try my code but it's not working, could any one help me please. [CODE
How can I open my Java desktop app by clicking on its file?
How can I open my Java desktop app by clicking on its file?  How can I open my Java desktop app by clicking on the file it creates? This app creates... file open by a double click from windows explorer, and to open inside BlueSky app
How to write to file using FileOutputStream
How to write to file using FileOutputStream  Hi friends, Please help me in java program. How to write to file using FileOutputStream? thanks,   Hi, To write a file using FileOutputStream, we have to use

Ads