Get the value of a file from a jfilechooser

I have a Java application with a Jbutton for choosing a local file and then represent the file with different types of charts. I want to get the file returned by JFileChooser and process it(split, add values in some lists...)

This is the JButton actionlistener:

JButton theButton = new JButton("Choose the file to represent");
theButton.addActionListener(new ActionListener() { 
     public void actionPerformed(ActionEvent event) {
        int returnValue = fileChooser.showOpenDialog(null);
        if (returnValue == JFileChooser.APPROVE_OPTION) {
            theFile = fileChooser.getSelectedFile();
            ReadGCFile.getValue(theFile);
        }       
}

});         
 desktopPane.add(theButton);
 theButton.setVisible(true);
 theButton.setBounds(20, 100, 250, 20);
 getContentPane().add(theButton);

Here I want to process the file:

    public static void readGCList(List<String> gcArrayList,
        List<String> gcStringList, List<String> gcDateList)
        throws NumberFormatException, IOException, ParseException {
    File newFile = null;
    String line = "";
    String[] tokens = null;
    FileReader fr = null;
    BufferedReader bufReader = null;
    try {

        fr = new FileReader(GDRT.theFile);  
        bufReader = new BufferedReader(fr);
        while ((line = bufReader.readLine()) != null) {
            line = line.replace(",", ".");
            tokens = line.split(";");

            gcDateList.add(tokens[0]);
            gcStringList.add(tokens[1]);
            gcArrayList.add(tokens[2]);
            gcArrayList.add(tokens[3]);
            gcArrayList.add(tokens[4]);

        }


    } catch (FileNotFoundException es) {
        System.out.println("The file was not found.");

    } catch (NullPointerException e) {
        System.out.println("No files were chosen !");
    }

    catch (IOException e) {
        bufReader.close();
    }

And I made a getValue method in which I do not know what to put:

 public static void getValue(File myFile) {
 System.out.println(myFile.getName());
 }

Answers


Consider a method like this:

public void processFile(File newFile) {
    try {

        getValue(newFile);
        FileReader fr = new FileReader(newFile);   
        BufferedReader bufReader = new BufferedReader(fr);
        Object line;
        while ((line = bufReader.readLine()) != null) {
            line = line.replace(",", ".");
            tokens = line.split(";");

            gcDateList.add(tokens[0]);
            gcStringList.add(tokens[1]);
            gcArrayList.add(tokens[2]);
            gcArrayList.add(tokens[3]);
            gcArrayList.add(tokens[4]);

        }
}

this you could call from within your ActionListener:

    int returnValue = fileChooser.showOpenDialog(null);
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        theFile = fileChooser.getSelectedFile();
        processFile(theFile);
    }  

Need Your Help

String replace function only for the content inside of a specified html tag

php string replace tags

I need to use string replace function but only for the content inside of a specified html tag.

alternative for web deployment projects in VS 2011

asp.net .net visual-studio webforms asp.net-4.5

I am trying to find out what is the alternative to using the Web Deployment projects in VS2011 as they do not seem to be supported anymore.