Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

read multiple files from bufferedreader and populate combobox java

Trying to create a program where i can load two files into a buffered reader and populate a JComboBox. I need it to load the first file called "currency.txt" into program when it is first run and then the user is able to loading a secondry file into the combobox to replace that. Right now i am having to do this manually. Can anyone help?

public static void loadFile(File file) {


                int itemCount = comboSelect.getItemCount();
                for(int i=0;i<itemCount;i++) {
                    comboSelect.removeAllItems();
                }
                Double value = (double) 0;
                try {

                    FileInputStream file1 = new FileInputStream("currency.txt");
                    FileInputStream file2 = new FileInputStream(file);

                    SequenceInputStream is=new SequenceInputStream(file1, file2);

                    BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));

                    String line = null;

                    while ((line = br.readLine()) != null && !line.isEmpty()) {
                         String[] values = line.split(",");

                         String currencyType = values[0];
                         String currencyValueTxt = values[1];
                         String currencySymbol = values[2];


                         try {
                             Double conversionValue = Double.parseDouble(currencyValueTxt);
                             listConversion.add(conversionValue);
                         }catch(Exception e) {
                             JOptionPane.showMessageDialog(null, "Number is missing");
                         }

                         comboSelect.addItem(currencyType);

                         symbolList.add(currencySymbol);

                    }

                }catch(Exception e) {
                    JOptionPane.showMessageDialog(null, "Please Load a file from the file menu");

                }
            }

The currency file is as follows: Euro (EUR), 1.359, €

US Dollars (USD), 1.34, $

Australian Dollars (AUD), 1.756, $

Canadian Dollars (CAD), 1.71, $

Icelandic króna (ISK), 140.84, kr

United Arab Emirates Dirham (AED), 4.92, د.إ

South African Rand (ZAR), 17.84, R

Thai Baht (THB), 43.58, ฿

This is the openfile method to populate the file

    private class OpenFileListner implements ActionListener{
    public void actionPerformed(ActionEvent e ) {
        JFileChooser chooser = new JFileChooser();
        chooser.showOpenDialog(chooser);
        File file = chooser.getSelectedFile();

        currencyPanel.loadFile(file);
    }
}

Comments