[platform-dev] Open a File and to display its content

  • From: "sharath.uddanti" < >
  • To:
  • Subject: [platform-dev] Open a File and to display its content
  • Date: Thu, 27 Sep 2012 08:31:37 -0400

Hi Geetha,

 Netbeans FileSystemApi provides FileObjec and you can use FileUtil class to 
get your work done.

Create a file object and convert to FileObject object when a button is 
clicked and read the content using FileObject as it has handful methods like 
asLines() etc.like


Code:

public void actionPerformed(ActionEvent ae) {
File projectToBeOpenedFile = projectChooser.getSelectedFile(); 

FileObject fileObject = null;
         if(projectToBeOpenedFile != null){
                    fileObject = FileUtil.toFileObject(projectToBeOpenedFile);
                      InputOutput inputOutput = 
IOProvider.getDefault().getIO(projectToBeOpenedFile.getName(), true);
             inputOutput.select();
             
            try {
                if(fileObject != null){
                    for(String str : fileObject.asLines()){
                         inputOutput.getOut().println(str);
                    }
                }
                
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
             
         }else{
             System.out.println("In the else part");
           JOptionPane.showMessageDialog(null, "No File has been Selected");
         }
    }


}




Here i am printing in output window provided by netbeans. Hope this will help.






[platform-dev] Open a File and to display its content

Geetha 09/27/2012

[platform-dev] Open a File and to display its content

sharath.uddanti 09/27/2012

Project Features

Project Links

About this Project

Platform was started in November 2009, is owned by Antonin Nebuzelsky, and has 138 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close