Could anybody help me with this code
1. want to read a file into an array.
2.three button should sort it 1st product name should sort it alphabetically, 2nd maximum stock level which sort by maximum value, 3rd price sort by maximum value on the top.

thanx
cheers
Demon

Recommended Answers

All 2 Replies

Hi
Can you te me please where you put your "Product.txt" file.

Well here I'll suppose that your text file is in the same package as the other java files.
If it is so please made this change:

class LoadFromFileListener implements ActionListener {

        public void actionPerformed(ActionEvent event) {
            try {
                InputStream u = getClass().getResourceAsStream("product.txt");
                BufferedReader  in = new BufferedReader(new InputStreamReader(u));
                String myEntry;
                while ((myEntry = in.readLine()) != null) {
                    StringTokenizer st = new StringTokenizer(myEntry, ",");
                    while (st.hasMoreTokens()) {
                        String ProdName = st.nextToken();
                        int quantity = Integer.parseInt(st.nextToken());
                        Double price = Double.parseDouble(st.nextToken());
                        myList.addLast(new ProductEntry(ProdName, quantity, price));

                        Display.setText("");
                        for (int i = 0; i < myList.size(); i++) {
                            Display.append(myList.get(i).toString());
                        }

                        Display.append("\n" + "TOTAL: " + myList.size() + "  Product(s) Found");
                    }
                }
                in.close();
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(null, "File not found!", "Error", JOptionPane.ERROR_MESSAGE);
            } catch (IOException ex) {
            }
        }
    }

Hope it helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.