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 8380815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:33:10+00:00 2026-06-09T16:33:10+00:00

For some reason this code results in a truncated text.txt file. It should (according

  • 0

For some reason this code results in a truncated text.txt file. It should (according to me) write out 1000 results, but the output file has various amounts of lines (depending on the run). Weirdly, the writing to the file stops in the middle of the write command, such that a line may not be complete. Currently, the last three lines of the text file for the latest run was as follows:

749, 78.97988, 97.80454, 99.6625, 94.00000015258789
750, 4.1745043, 86.64212, 107.59311, 71.00000008583069
751,

and that’s it. Nothing else after that.

Here is the code:

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Random;

public class ColorGrayScale {

/**
 * @param args
 * @throws IOException
 */
@SuppressWarnings("resource")
public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    Writer out = new BufferedWriter(new FileWriter("test.txt"),16*1024);
    Random generator = new Random();
    float red = 0, green = 0, blue = 0;
    int i = 0;

    while (i<1000) {

        float grey = generator.nextInt(127) + 64;
        int sequence = generator.nextInt(6) + 1; // to pick from 1 of six
                                                    // orders
        switch (sequence) { // the various orders that red green and blue
                            // are going to be in
        case 1:
            red = (float) (generator.nextFloat() * (grey / .21));
            green = (float) (generator.nextFloat() * ((grey - (red * .21)) / .71));
            blue = (float) ((grey - (red * .21) - (green * .71)) / 0.08);
            break;
        case 2:
            red = (float) (generator.nextFloat() * (grey / .21));
            blue = (float) (generator.nextFloat() * ((grey - (red * .21)) / .08));
            green = (float) ((grey - (red * .21) - (blue * .08)) / 0.71);
            break;
        case 3:
            green = (float) (generator.nextFloat() * (grey / .71));
            red = (float) (generator.nextFloat() * ((grey - (green * .71)) / .21));
            blue = (float) ((grey - (red * .21) - (green * .71)) / .08);
            break;
        case 4:
            green = (float) (generator.nextFloat() * (grey / .71));
            blue = (float) (generator.nextFloat() * ((grey - (green * .71)) / .08));
            red = (float) ((grey - (green * .71) - (blue * .08)) / .21);
            break;
        case 5:
            blue = (float) (generator.nextFloat() * (grey / .08));
            red = (float) (generator.nextFloat() * ((grey - (blue * .08)) / .21));
            green = (float) ((grey - (blue * .08) - (red * .21)) / .71);
            break;
        case 6:
            blue = (float) (generator.nextFloat() * (grey / .08));
            green = (float) (generator.nextFloat() * ((grey - (blue * .08)) / .71));
            red = (float) ((grey - (blue * .08) - (green * .71)) / .21);
            break;
        }
        if (red < 256 && blue < 256 && green < 256) {
             out.write("" + i + ", " + red + ", " + green + ", " + blue
                    + ", " + (.21 * red + .71 * green + 0.08 * blue + "\n"));
            i++;
        }
    }
}

}

  • 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-09T16:33:11+00:00Added an answer on June 9, 2026 at 4:33 pm

    You forgot to close() the writer, so you never gave it a chance to flush buffered output to disk.

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

Sidebar

Related Questions

For some reason, this code does not actually draw my bitmap file... or show
for some reason this code wont work, it doesn't seem to read the javascript.php
For some reason this line of code is giving me quite a problem. struct
For some reason my code here (this is the entire thing) doesnt actually render
For some reason, this line of code is returning undefined for $(this).attr(href) $(a).attr(href, javascript:page('
For some reason this statement is working fine: vms.Where(vm => vm.MessageType == ValidationMessage.EnumValidationMessageType.Warning) But
For some reason this text isn't being centered. #highlightheader { background-color:#006600; color:white; font-size:30px; text-align:center;
For some reason the following C++ code results in a segmentation fault: #include <sstream>
I have this code, and for some reason my $.post function fires twice in
It pains me to ask this, but, for some reason I have not been

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.