I am trying to save an integer matrix to the csv file. My code is listed as follows.

try
        {
          FileWriter writer = new FileWriter("test.csv");
          
             for(int i = 0; i < row; i++)
             {
               
                 for (int j=0; j<(column-1); j++)
                 {
                	 writer.append(Matrix[i][j]);
                	 writer.append(',');
                 }
            	
                   writer.append(Matrix[i][j]);
                   writer.append('\n');
                   writer.flush();
             }
             writer.close();
          }
        
        catch(Exception e)
        {
          e.printStackTrace();
        }

However, the Eclipse gives the following error message:

method append(CharSequence) in the type Writer is not
applicable for the arguments (int)

Please let me know how to fix this issue. Thanks.

Use String.valueOf(int) to convert your int to a string for the writer.

Edited 5 Years Ago by Ezzaral: n/a

Start with this...

BufferedWriter Text_Output;
   String File_Out = "Output.csv";

      try
      { Text_Output = new BufferedWriter (new FileWriter (File_Out, Append)); }
      catch (IOException IOE)
      {  }

      try
      {
         Text_Output.write ("Data, Data, Data");
         Text_Output.newLine ();
      }
      catch (IOException IOE)
      {  }

      try
      { Text_Output.close (); }
      catch (IOException IOE)
      {  }

and modify it to suit your needs (looping, etc.)

Absolutely do NOT start with any code that has

catch (IOException IOE)
{ }

If it doesn't work because of an Exception you'll never be able to debug it.
At the very least replace all those with

catch (IOException e) { 
  e.printStackTrace(); 
}

Edited 5 Years Ago by JamesCherrill: n/a

Whoa... Easy James!
I was expecting them to fill in their own code in the exception catches.
It was just a framework to get them started.
(I'm not going to give them MY code to handle the exceptions.)

Edited 5 Years Ago by hfx642: n/a

Hi hhfx642, We have an awful lot of absolute beginners here, and leaving catch clauses blank is one of the mistakes they often make (with obvious consequences). I wasn't having a go at you, I was just worried about newbies taking that template as a starting point without realising the importance of diagnosing exceptions. :-)
J

Understood! :)
Next time, I'll make it more obvious for them to put their own code in where appropriate.

This question has already been answered. Start a new discussion instead.