Member Avatar for Big-D2xL

I'm trying to create a .txt reader and inserting the read data to the cleansheets software we are editing in class but instead of putting the correct data it does nothing. I made some prints and this is what I obtain:

D:\Documentos\Desktop\ImportTest.txt
cacacaca ----- [[Ljava.lang.String;@73a175]
cacacaca ----- [[Ljava.lang.String;@73a175, [Ljava.lang.String;@364cf2]
cacacaca ----- [[Ljava.lang.String;@73a175, [Ljava.lang.String;@364cf2, [Ljava.lang.String;@5f3215]
cacacaca ----- [[Ljava.lang.String;@73a175, [Ljava.lang.String;@364cf2, [Ljava.lang.String;@5f3215, [Ljava.lang.String;@5a421d]
cacacaca ----- [[Ljava.lang.String;@73a175, [Ljava.lang.String;@364cf2, [Ljava.lang.String;@5f3215, [Ljava.lang.String;@5a421d, [Ljava.lang.String;@1f528ea]
cacacaca ----- [[Ljava.lang.String;@73a175, [Ljava.lang.String;@364cf2, [Ljava.lang.String;@5f3215, [Ljava.lang.String;@5a421d, [Ljava.lang.String;@1f528ea, [Ljava.lang.String;@12aa4ba]
cacacaca ----- [[Ljava.lang.String;@73a175, [Ljava.lang.String;@364cf2, [Ljava.lang.String;@5f3215, [Ljava.lang.String;@5a421d, [Ljava.lang.String;@1f528ea, [Ljava.lang.String;@12aa4ba, [Ljava.lang.String;@e4e190]


cocococo ----- [[Ljava.lang.String;@a011bb
cocococo ----- [[Ljava.lang.String;@a011bb
cocococo ----- [[Ljava.lang.String;@a011bb
cocococo ----- [[Ljava.lang.String;@a011bb
cocococo ----- [[Ljava.lang.String;@a011bb
cocococo ----- [[Ljava.lang.String;@a011bb
cocococo ----- [[Ljava.lang.String;@a011bb
Done

This is the code I made so far:

try {
            //Creates a file
            JFileChooser chooser;
            File ficheiro = null;
            chooser = new JFileChooser();

            //Creates a filter to 'TXT'
            chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter());
            FileFilter filterTXT = new FileNameExtensionFilter("TXT File", "txt");
            chooser.setFileFilter(filterTXT);

            //Opens the dialog window to choose the file to import.
            int success = chooser.showOpenDialog(null);
            if (success == JFileChooser.APPROVE_OPTION) {
                ficheiro = chooser.getSelectedFile();

                InputStream is = new FileInputStream(ficheiro);
                Reader streamReader = new InputStreamReader(is);
                BufferedReader reader = new BufferedReader(streamReader);

                System.out.println(ficheiro.toString());
                // Reads content of rows
                String line;
                int columns = 0;
                List<String[]> rows = new LinkedList<String[]>();
                while ((line = reader.readLine()) != null) {
                    String[] row = line.split(";");

                    rows.add(row);
                    if (row.length > columns) {
                        columns = row.length;
                    }
                    System.out.println("cacacaca ----- " + rows);

                }
                System.out.println("\n");
                // Builds content matrix
                String[][] content = new String[rows.size()][columns];
                int i = 0;
                for (String[] row : rows) {
                    content[i++] = row;
                    System.out.println("cocococo ----- " + content);
                }

                reader.close();

                Workbook workbook = new Workbook(content);
            }
            System.out.println("Done");

        } catch (IOException ex) {
            Logger.getLogger(ImporterAction.class.getName()).log(Level.SEVERE, null, ex);
        }

If someone can help, I'd aprecciate! :)

You can't just print an array by saying
System.out.println(myArray);
all you get is a coded output like
[[Ljava.lang.String;@73a175]
that says it's an array of Strings at a particular address (etc)

Either print the elements one at a time in a loop, or use a method from the Arrays class to convert the array to a printable string, eg
System.out.println(Arrays.toString(myArray));

Member Avatar for Big-D2xL

JamesCherrill firstly, yes I was forgetting to do that :p
secondly, the mai problem was that I wasn't beeing able to insert the data in the place I wanted, after a while I managed to do it (writing a little for cicle)...

tring "Changed".
     *
     * @param event the event that was fired
     */
    public void actionPerformed(ActionEvent event) {

        try {
            //Creates a file
            JFileChooser chooser;
            File ficheiro = null;
            chooser = new JFileChooser();

            //Creates a filter to 'TXT'
            chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter());
            FileFilter filterTXT = new FileNameExtensionFilter("TXT File", "txt");
            chooser.setFileFilter(filterTXT);

            //Opens the dialog window to choose the file to import.
            int success = chooser.showOpenDialog(null);
            if (success == JFileChooser.APPROVE_OPTION) {
                ficheiro = chooser.getSelectedFile();

                InputStream is = new FileInputStream(ficheiro);
                Reader streamReader = new InputStreamReader(is);
                BufferedReader reader = new BufferedReader(streamReader);

                // Reads content of rows
                String line;
                int columns = 0;
                List<String[]> rows = new LinkedList<String[]>();
                while ((line = reader.readLine()) != null) {
                    String[] row = line.split(";");
                    for (int i = 0; i < row.length; i++) {
                        try {
                            uiController.getActiveSpreadsheet().getCell(i, columns).setContent(row[i]);
                        } catch (FormulaCompilationException ex) {

                        }
                    }
                    columns++;
                }
                reader.close();
            }
            System.out.println("Done");

        } catch (IOException ex) {
            Logger.getLogger(ImporterAction.class.getName()).log(Level.SEVERE, null, ex);
        }
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.