1

I try and write my array to a file, however instead of my data, all I get is two cells; One is [Ljava.lang.String;@7b1ddcde and the other is [Lorg.supercsv.cellprocessor.ift.CellProcessor;@658fb1f7 I have no idea how on earth this is happening, as my array is actually a very nice set of data and works when I print it to the console.

My table has all of the headers and required cells, it's just that these weird errors take up the first two cells and no other data is written.

My CellProcessor method is just full of new Optional(), so I don't think that's the issue here. Here is the entire method. I am so sorry, my code is horrible it was made in a hurry.

static String[] writeWithCsvListWriter(String filename) throws Exception {
    ICsvListWriter listWriter = null;
    try {
            listWriter = new CsvListWriter(new FileWriter(Main.filename + ".csv"),
                    CsvPreference.STANDARD_PREFERENCE);

            final CellProcessor[] processors = getProcessors();
            final String[] header = new String[] { "Year", "mm", "Max Temp", "Min Temp",
                    "af days", "Rain", "Sun" };

            listWriter.writeHeader(header);

            FileReader fileReader = new FileReader(filename);
            BufferedReader bufferedReader = new BufferedReader(fileReader);
            List<String> lines = new ArrayList<String>();
            String line = null;

            int i = 0;
            while ((line = bufferedReader.readLine()) != null) {
                if(line.startsWith("   2010")){
                    try {
                        String[] splitArray = line.split("\\s+");
                        System.out.println("Writing Array");
                        listWriter.write(splitArray, processors);
                    } catch (PatternSyntaxException ex) {
                    }
                }
                i++;
            }
            bufferedReader.close();
    } finally {
            if( listWriter != null ) {
                    listWriter.close();
            }
    }
    return null;
}
3
  • 7
    Show your code. You're getting the default toString of your arrays. Commented Jan 23, 2013 at 21:06
  • Yeah, how would I stop it from doing that? Commented Jan 23, 2013 at 21:14
  • 1
    I recommend against swallowing exceptions silently, btw. Commented Jan 23, 2013 at 21:19

1 Answer 1

2

Looking at the ICsvListWriter API, it looks to me like you are getting the method write(Object... columns), rather than write(List<?> columns, CellProcessor[] processors).

The method you are trying to call appears to be expecting a List as the first argument, rather than an array, so transform your array to a list first, then attempt to write it. Something like;

String[] splitArray = line.split("\\s+");
List list = Arrays.asList(splitArray);
System.out.println("Writing Array");
listWriter.write(list, processors);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.