Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:30:08+00:00 2026-06-05T11:30:08+00:00

I am trying to write an writer in Java which takes integer values out

  • 0

I am trying to write an writer in Java which takes integer values out of an ArrayList for the first row and column and a float[][] for the rest and formats it into a CSV. Doing this my first column gets weird and I can’t find the problem. I would be really happy for any suggestions or help. Here is my code:

public static void resulttofile(List<Nm_item> nmvector,
        float[][] cor_matrix, String filename) {
    try {
        FileWriter writer = new FileWriter(new File(filename + ".csv"));
        for (int i = nmvector.get(0).row; i <= nmvector
                .get(nmvector.size() - 1).row; i++) {
            writer.write(sepw + nmvector.get(i).nm);
        }
        writer.write(System.getProperty("line.separator"));
        for (int i = nmvector.get(0).row; i <= nmvector
                .get(nmvector.size() - 1).row; i++) {
            writer.write(nmvector.get(i).nm);

            for (int j = nmvector.get(0).row; j <= nmvector.get(nmvector
                    .size() - 1).row; j++) {
                writer.write(sepw + cor_matrix[i][j]);
            }
            writer.write(System.getProperty("line.separator"));
        }

        writer.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Results saved to " + filename + ".csv");
}

and the output (cropped):

        350 351 352 353
?   0   0.003   0.171   0.001
?   0.003   0   0.274   0
è   0.163   0.271   0   0.345
Ü   0   0   0.35    0
?   0.008   0.019   0.326   0.044
?   0.008   0.016   0.199   0.015
?   0.015   0.037   0.361   0.04
?   0.029   0.023   0.171   0.023
?   0.038   0.042   0.186   0.038
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:30:09+00:00Added an answer on June 5, 2026 at 11:30 am

    Try:

    writer.write(Integer.toString(nmvector.get(i).nm));
    

    Or, as OldCurmudgeon says:

    writer.write("" + nmvector.get(i).nm);
    

    The point is that FileWriter contains more than one write method. There is write(int) and write(String). The first one doesn’t write the number, it writes the character that corresponds to the number given, so for example writer.write(88) will output the character ‘X’, writer.write(89) will output ‘Y’, and you can guess what writer.write(90) will give you. You need to convert the integer to a String so that the right write() method is called.

    The second form writer.write("" + number) works because when you add a number to a String the Java compiler will automatically convert the number into a String for you. This is why writer.write(sepw + nmvector.get(i).nm); works but writer.write(nmvector.get(i).nm); doesn’t.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a Java program or Hadoop Pig script which will
I'm trying to write a method which takes a Map[K, Collection[V]] and converts it
I am trying to write some code which retrieves the first 10 words of
I have the following C-code which I am trying to re-write in java. I
I'm trying to write a Java function that takes a Class<?> and returns a
I am new to programming and Java and trying to write a program which
I am trying to write a program in java which can count number of
I am trying to write a simple java program which returns me all the
I'm trying to write a small internal DSL in Java which generates an tree
I am trying to write java code to access a table 'customer' with columns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.