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

  • Home
  • SEARCH
  • 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 3303610
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:58:30+00:00 2026-05-17T20:58:30+00:00

This is yet another of my Java questions. Please take a look at this

  • 0

This is yet another of my Java questions.

Please take a look at this code:


public static void main(String[] args) {
  if( args.length != 5) {
   System.out.println("Error. Wrong number of params!");
   System.exit(0);
  }
  File file = new File(args[0]);
  try {
   BufferedImage image = ImageIO.read(file);
   FileWriter fstream = new FileWriter("output.txt");
         BufferedWriter out = new BufferedWriter(fstream);
   int avg = 0;
      int w = image.getWidth();
      int h = image.getHeight();
      Rectangle r = new Rectangle();
      double whiteHelp = Double.parseDouble(args[4]);
      avg = (int) (avg / 1);
      int startX = Integer.parseInt(args[2]);
      int startY = Integer.parseInt(args[3]);
      r.width = r.height = Integer.parseInt(args[1]);
      for(int i = startY; i <= h - r.height; i += r.height) {
       for(int j = startX; j <= w - r.width; j += r.width) {
        r.x = j;
        r.y = i;
        avg = getTileColor(r, image, whiteHelp);
        //System.out.print(avg);
        out.write(avg);
       }
       //System.out.println();
       out.write("\n");
      }
      out.close();

      image.flush();
      System.out.println("Finished parsing the image. Solving...");
  } catch (Exception e) {
   System.out.println("Error.");
   e.printStackTrace();  
  }

 } 

In output.txt I only get non-readable text, as if opening binary file for example.

Is there some king of problem when BufferedImage and BufferedWriter being instantiated simultaneously? I’m using the same procedure to write to file in another class, where one file is opened for reading, and another is opened for writing, and things work just fine.

p.s. How to enter &lt character without breaking the code??? Do I need to enter it as & lt ;?

Thanks

  • 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-05-17T20:58:31+00:00Added an answer on May 17, 2026 at 8:58 pm

    You invoke

    out.write(avg)
    

    to write the int avg to the output.

    This will invoke the method BufferedWriter.write(int); this will write out the character with the Unicode code point avg. This is probably not what you want ;-).

    To print the number avg in decimal format, use

    out.write(String.valueOf(avg))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, this is yet another question on producer/consumer in Java. My variant is that
Yet another data structure doubt. I will get straight to it. This is what
I guess this question will sound familiar, but I am yet another programmer baffled
Please do not mark it as a dupe of this question just yet: Bold
This is not yet another question about the difference between abstract classes and interfaces,
I have gone through various questions about public inner classes in this forum, however
I have a set of questions regarding Java multithreading issues. Please provide me with
This questions seems to be so simple, yet I didn't find the mistake. Ok,
Yet another question on this I know, but let me just say I looked
I've been caught by yet another deadlock in our Java application and started thinking

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.