Home Answers Viewqa Java-Beginners How to open a file in java using JFileChooser

 
 


Mohammed Irfan
How to open a file in java using JFileChooser
2 Answer(s)      2 years and 2 months ago
Posted in : Java Beginners

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.









Related Pages:
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
JFileChooser - Swing AWT
JFileChooser  Hi,iam using jfilechooser to select a directory....now the prob is iam able to open only the files in the directory....actually i have... directory one by one...........can any one plzzzz assist me how to read the sub
Using a JFileChooser - Java Beginners
Using a JFileChooser  Dear Editor, How to select an image from JFileChooser & add the image in mySQL5 database? Thanks in advanced. Regards... void main(String[] args) { JFileChooser chooser = new JFileChooser(); int
JFileChooser - Java Beginners
JFileChooser  How to create a GUI application that allows a user to select a text file (using the JFileChooser). The program will then count the number of words in the selected file and display the result containing the name
JFileChooser
Java: JFileChooser The javax.swing.JFileChooser class is used to create file choosers for selecting files or directories to open or save. To Create an Open File Chooser The sample code below uses JFileChooser in the Open button
How to select default FileFilter when creating a JFileChooser dialog?
How to select default FileFilter when creating a JFileChooser dialog?  Hi, In my swing application I want my application to open the my specific directory say "c:\mydirectory" when browse button is clicked. How to select
how to open java
how to open Java  how to open java file simple Java Example
how to open a file with a jbutton? - Java Beginners
how to open a file with a jbutton?  Hello Is it possible that by clicking on a button it can open java html file or doc exists on the pc? I searched and I found that it is possible to open a web page so I tried to open
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 Open Picture From M.S. Access Database using Java Servlet ?
How to Open Picture From M.S. Access Database using Java Servlet ?  ... Database But i m still not able to open this picture through Java using M.S. Access and i wants to open this Picture On Web Browser using Java Servlet anybody can
Open TextFile on JButton Click - Java Beginners
Open TextFile on JButton Click  Hello Sir I Want to open TextFile on JButton Click. plz Help Me  Hi Friend, Do you want to simply open the text file or you want to open the file using JFileChooser,read that file
How to Open Text or Word File on JButton Click in Java - Java Beginners
How to Open Text or Word File on JButton Click in Java  How to Open Text or Word File on JButton Click in Java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
open word document
open word document  how to open a word document ??   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
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
open document
open document  open a word document using jsp   Please go through the following link: Java Read word document file The above link will provide an example that will read the document file using POI library in java
Open a .doc file by click on the link using struts - Struts
Open a .doc file by click on the link using struts   I want to open a doc extension file when i click a link on jsp page .I know only about which is write in web.xml but not exactly know how i do this.Plz any one can help me
C file open example
C file open example       This section demonstrates you how to open a file in C.  The header.... Here we are going to open a file using library function fopen(). You can see
create, edit ,open simple documents using java - Swing AWT
create, edit ,open simple documents using java   In my program I... want to use Java Swing or JSP? Do you want to create word document file... in text area? Then how to transfer text in that document back to text area
How to Open JSP?
How to Open JSP?       In this section you learn How to Open JSP in text editor. The JSP file is simple text file with HTML code embedded with Java Code. Since JSP
open a bufferedwriter file in append mode - Java Beginners
open a bufferedwriter file in append mode  hi.. i jus want knw how to opena bufferedwriter file in append mode..  Hi friend, FileWriter... simply overwrite the contents in the file by the specified string but if you put
PHP Open Excel File in browser - PHP
PHP Open Excel File in browser  How we can open an excel file using PHP code. I don?t want to let the user to download it rather I would like to get it open in the web browser. Any help would be great. Thank you very much
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
read from cmd syntax and open the file
read from cmd syntax and open the file  i have to read the name of the database e.g., "database.txt" file from a cmd syntax and open it: java FindKeys database=db.txt;minjoinrows=integer|all how can i do
read from cmd syntax and open the file
read from cmd syntax and open the file  i have to read the name of the database e.g., "database.txt" file from a cmd syntax and open it: java FindKeys database=db.txt;minjoinrows=integer|all how can i do
Java file browse
Java file browse In this section, you will learn how to browse a file... file or directory from a list. The JFileChooser class opens up a file browser... returns the name of the file. showOpenDialog()- This method of JFileChooser
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
Java file browser
Java file browser In this section, you will learn how to browse the file... of JFileChooser class open the dialog and allow to select the file. getSelectedFile()- This method of JFileChooser class returns the selected file. getName
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
How to write to file using FileWriter
How to write to file using FileWriter  hi, How to write to file using FileWriter thanks,   Hi, To writing in a file in Java program we... of the FileWriter class can be created using the following of its constructor i.e. FileWriter
Java File Chooser
Java File Chooser Java provides javax.swing.* package that is really... purposes. Among them, JFileChooser is a standard dialog for selecting a file from.... getSelectedFile()- This method of JFileChooser class returns the selected file
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 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 copy a file in java
How to copy a file in java In this section you will learn about how to copy a content of one file to another file. In java, File API will not provide any.... In another way we can copy using File I/o Stream. Example:  Java Code to copy
how to start intergrated webcam of a laptop without calling its exe file using java only - Java Beginners
how to start intergrated webcam of a laptop without calling its exe file using java only  how to open integrated webcam of a laptop without calling its exe file using java only?.simply what i am asking is that is there any method
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
need to open a file that is in server using jsp
need to open a file that is in server using jsp   im doing a web... open link it should be opened in jsp.downlaoding part was done by me. wt i need is just want to open a pdf in jsp.is it possible to open sever file from jsp.Plz
Open Source Groupware
, diverse and standards based groupware solution available.   How do Open... project to develop a full-featured groupware client application using Java, eventually... Open Source Groupware Open Groupware  Open Group
File
File   How to find all files in our local computer using java
How to upload file using JSP?
How to upload file using JSP?   Hi all, I m the beginner in JSP, I want to upload file on server in specific folder.   1)page.jsp: <%@ page language="java" %> <HTML> <HEAD><TITLE>Display
JavaScript Open file
; In this section, you will learn how to open and read the file in JavaScript. You can... JavaScript Open file... the file and get the appropriate file to read. On clicking the "Open 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 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
Open Source Content Management
Management Systems In this article we'll focus on how Open Source and CMS combine... for Evaluating Open-Source Content Management Systems Using a content management...; How to Choose an Open Source Content Management System The most
File IO
are planning to learn file management using Java IO package.This class is available... Problem: How to you store objects in a file? Writes... The Java IO package is used to perform various input/output processing
Java Swing Open Browser
Java Swing Open Browser Java provides different methods to develop useful applications. In this section, you will learn how to create an example that will open the specified url on the browser using java swing. This example will really

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.