Problem outputting to the screen using  FileDescriptor.out

I have the following program that reads prime numbers from a binary file. The issue is that the numbers are not printing to the screen using
FormatWriter out = new FormatWriter(
       new BufferedWriter(
       new FileWriter(FileDescriptor.out)));The numbers are being read from the file as if I unblock the line
// System.out.println(primes[j]); the numbers are printed to the screen.
I have pasted the code below and the code that creates the prime numbers file.
Thanks for any help.
package readprimes;
import java.io.*;
public class ReadPrimes {
   public static void main(String[] args) {
       File myPrimes;
       DataInputStream primesIn;
        try{
            String directory = "C:/JunkData";
            String fileName = "Prime.bin";
            myPrimes = new File(directory, fileName);
             primesIn = new DataInputStream(new FileInputStream(myPrimes));
        catch(FileNotFoundException e){
            return;
        catch(IOException e){
            return;
    FormatWriter out = new FormatWriter(
       new BufferedWriter(
       new FileWriter(FileDescriptor.out)));
        long[] primes = new long[6];
        boolean EOF = false;
        while(!EOF){
            int index = 0;
            try{
                for(index = 0; index < primes.length; index++)
                    primes[index] = primesIn.readLong();
                   catch(IOException e){
            return;
//             catch(EOFException e){
//                 EOF =  true;
            for(int j = 0;j < index; j++){
         //       System.out.println(primes[j]);
                out.print(primes[j]);
                out.println();
out.close();
package readprimes;
import java.io.PrintWriter;
import java.io.*;
public class FormatWriter extends PrintWriter{
    private int width = 10;
    public FormatWriter(Writer output){
        super(output);
    public FormatWriter(Writer output, int width){
        super(output);
        this.width = width;
    public FormatWriter(Writer output, boolean autoflush){
        super(output, autoflush);
        public FormatWriter(Writer output, boolean autoflush, int width){
        super(output, autoflush);
        this.width = width;
Class that creates the prime number file
package bufferedoutput;
import java.io.*;
public class TryPrimesOutput {
   public static void main(String[] args) {
       long[] primes = new long[200];
       primes[0] = 2;
       primes[1] = 3;
       int count = 2;
       long number = 5;
       outer:
       for(; count < primes.length; number +=2L)
           long limit = (long)Math.ceil(Math.sqrt((double)number));
           for(int i = 1; i <count && primes<= limit; i++)
if(number%primes[i]==0)
continue outer;
primes[count++] = number;
try
String dirName = "c:\\JunkData";
String fileName = "Prime.bin";
File myPrimeDir = new File(dirName);
if(!myPrimeDir.exists())
myPrimeDir.mkdir();
else
if(!myPrimeDir.isDirectory())
System.err.println();
return;
File primesFile = new File(myPrimeDir, fileName);
primesFile.createNewFile();
DataOutputStream primesStream = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(primesFile)));
for(int i = 0; i <primes.length;i++)
primesStream.writeLong(primes[i]);
primesStream.close();
catch(IOException e){
System.out.println("IOExcetoptj");

Indeed. It isn't obvious to me what the result of new FileWriter(FileDescriptor.out) would result in, but your test appears to show that it doesn't result in something which can be used to output to the console.

Similar Messages

  • Can't connect to my iMac when energy saver is active. Screensaver is okey, but if the screen is blacked out, I cant connect using vnc/teamviewer/logmein. SSH is okey. :(

    Can't connect to my iMac when energy saver is active.
    Screensaver is okey, but if the screen is blacked out, I cant connect using vnc/teamviewer/logmein. SSH is okey.
    Anyone else having this issue? Worked great in snow leopard. Updated to 10.7.1
    //Niklas

    Ok so I happened to figure it out while on the phone to apple support. Even though the guy was very nice, I think I knew more than him! He was explaining very basic resolution principles I played about. I had the second option in displays resolution. All I did was unplug the HDMI cable, click on 'best for display' then plugged the HDMI in and my resolution on the normal monitor changed to the normal blue, then went black momentarily and then changed to a strange resolution but another window appeared that said SONY BRAVIA HDMI at the top! Hey presto! Don't know why it didn't do it yesterday - I probably left the HDMI cable in or something! Oh well. Problem solved!

  • With the new IOS 7 mi iPhone has problems with the screen, I go out once stripes, and Apple told me it is the software. help when there is a new update?????

    with the new IOS 7 mi iPhone has problems with the screen, I go out once stripes, and Apple told me it is the software. help when there is a new update?????

    We are users here.  We cannot possibly know when a new update will be available.

  • Since I downloaded the newest update, my phone only rings or makes text sounds about 10% of the time. It can be sitting in front of me and a call or text comes in. No sound, just a msg on the screen. Anyone out there having that problem?

    Since I downloaded the newest update, my phone only rings or makes text sounds about 10% of the time. It can be sitting in front of me and a call or text comes in. No sound, just a msg on the screen. Anyone out there having that problem?  It's not a problem in the settings as I set the rings and tones I want. The rare one comes thru with sound. I never had any problems before update.

    No, sounds like when you dropped it an cracked the screen it may have also damaged the logic board or the repair person damaged a cable.

  • I was updating google translate on my phone then the screen just black out. I thought battery went flat but after I put on charge, it's still not working. Please help!

    I was updating google translate on my phone then the screen just black out. I thought battery went flat but after I put on charge, it's still not working. Please help!

    Hello 74birdy
    The article below will assist with troubleshooting your iPhone not responding.
    iOS: Not responding or does not turn on
    http://support.apple.com/kb/TS3281
    Thanks for using Apple Support Communities.
    Regards,
    -Norm G.

  • Clearing the screen using java

    hi
    how to clear the screen using a java program

    for (int n = 0; n < 24; n++) System.out.println();
    Even better: don't clear the screen. The program I ran before your program printed out very important things. If your program throws away those important things then I will not like you or your program.

  • [svn] 3672: Removing the commonly used getUnqualifiedClassName out of the less commonly used utility class to reduce SWF size for the general case .

    Revision: 3672
    Author: [email protected]
    Date: 2008-10-15 16:54:51 -0700 (Wed, 15 Oct 2008)
    Log Message:
    Removing the commonly used getUnqualifiedClassName out of the less commonly used utility class to reduce SWF size for the general case.
    Reviewer: Gordon
    QE: No
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/mx/graphics/graphicsClasses/TextGraphicEleme nt.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/core/UIComponent.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/core/UITextField.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/effects/Effect.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/effects/EffectInstance.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/managers/SystemManager.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/utils/NameUtil.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/utils/ObjectUtil.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/utils/OrderedObject.as

    In general theory, one now has the Edit button for their posts, until someone/anyone Replies to it. I've had Edit available for weeks, as opposed to the old forum's ~ 30 mins.
    That, however, is in theory. I've posted, and immediately seen something that needed editing, only to find NO Replies, yet the Edit button is no longer available, only seconds later. Still, in that same thread, I'd have the Edit button from older posts, to which there had also been no Replies even after several days/weeks. Found one that had to be over a month old, and Edit was still there.
    Do not know the why/how of this behavior. At first, I thought that maybe there WAS a Reply, that "ate" my Edit button, but had not Refreshed on my screen. Refresh still showed no Replies, just no Edit either. In those cases, I just Reply and mention the [Edit].
    Also, it seems that the buttons get very scrambled at times, and Refresh does not always clear that up. I end up clicking where I "think" the right button should be and hope for the best. Seems that when the buttons do bunch up they can appear at random around the page, often three atop one another, and maybe one way the heck out in left-field.
    While I'm on a role, it would be nice to be able to switch between Flattened and Threaded Views on the fly. Each has a use, and having to go to Options and then come back down to the thread is a very slow process. Jive is probably incapable of this, but I can dream.
    Hunt

  • When I run this script nothing is output to the screen or spooled to a file

    When I run this script nothing is output to the screen or spooled to a file. What do I need to do to get output from this script.
    SET SERVEROUTPUT ON size 100000
    DECLARE
    v_schema     Varchar2(50);
    v_statement      Varchar2(500);
    v_name varchar2(30);
    v_id varchar2(8);
    v_pwd varchar2(16);
    v_acct varchar2(16);
    CURSOR get_schemas IS
    SELECT DISTINCT owner
    FROM all_tables
    WHERE table_name = 'USERID'
    ORDER BY owner;
    BEGIN
    OPEN get_schemas;
    LOOP
    FETCH get_schemas INTO v_schema;
    EXIT WHEN get_schemas%NOTFOUND;
              v_statement := 'SELECT name,usid,passwd,acctnum INTO v_name,v_id,v_pwd,v_acct FROM '||v_schema||'.userid';
              execute immediate v_statement;
              DBMS_OUTPUT.PUT_LINE('Name='||v_name||' ID='||v_id||' PW='||v_pwd||' AC='||v_acct);          
    END LOOP;
    CLOSE get_schemas;
    END;
    /

    Do I include several variables after the INTO or just
    one?
    How do I loop through the record and print the
    individual variables?
    I appreciate your assistance!He already gave you the answer above:
    v_statement := 'SELECT name,usid,passwd,acctnum FROM ' || v_schema ||
    '.userid';
    execute immediate v_statement
    INTO v_name, v_id, v_pwd, v_acct;
    If this is not printing any output, it is because you don't have a table named USERID... what are you trying to do?

  • I have an iphone 4 and i'm having lot of problems: my back camera is blurred although my front camera is fine and working normal. my biggest problem is that the screen is showing colored horizontal lines

    I have an iphone 4 and i'm having lot of problems:
    _ my back camera is blurred although my front camera is fine and working normally
    _ my biggest problem is that the screen is showing colored horizontal lines(as perhaps electrical problems). The phone did fell and I already changed its back and front but everything was normal until these problems appeared suddenly
    Please can somebody help me to solve it and tell me what are the reasons?
    Thx

    you can try turning it off and on again, but i doubt that's gonna work, that sounds like more of a hardware issue. Your best bet may be to contact apple and seek service or replacement

  • I would like to be able to pipe output to the screen as well as to 'append' it to an array

    I would like to be able to pipe output to the screen as well as to 'append' it to a variable.
    For example, for something like this:
    $result =@()
    $result += Invoke-Command -cn $servers -scriptblock { foo }
    I would like to be able to see on the screen the running output of
    Invoke-Command -cn $servers -scriptblock { foo }
    as well as capture each result to the $result variable.

    Just wrap the expression in parens:
    ($result += Invoke-Command -cn $servers -scriptblock { foo })
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • My iphone 4 will not charge in the plug or connect to my laptop but my ipod 4th gen does. what could the problem be because the screen to show it needs charging will not come up and it will not restart by holding the home button and lock button. thanks

    my iphone 4 will not charge in the plug or connect to my laptop but my ipod 4th gen does. what could the problem be because the screen to show it needs charging will not come up and it will not restart by holding the home button and lock button. thanks

    Hi there,
    I would recommend taking a look at the troubleshooting steps found in the article below.
    iPhone: Hardware troubleshooting
    http://support.apple.com/kb/ts2802
    -Griff W

  • I can't get this script to produce output to the screen or a log file

    I can't get this script to produce output to the screen or a log file of the select statement results as they are executed.
    SET SERVEROUTPUT ON size 100000
    DECLARE
    v_schema     Varchar2(50);
    v_statement      Varchar2(500);
    v_name varchar2(30);
    v_id varchar2(8);
    v_pwd varchar2(16);
    v_acct varchar2(16);
    CURSOR get_schemas IS
    SELECT DISTINCT owner
    FROM all_tables
    WHERE table_name = 'USERID'
    ORDER BY owner;
    BEGIN
    OPEN get_schemas;
    LOOP
    FETCH get_schemas INTO v_schema;
    EXIT WHEN get_schemas%NOTFOUND;
              v_statement := 'SELECT name,usid,passwd,acctnum INTO v_name,v_id,v_pwd,v_acct FROM '||v_schema||'.userid';
              execute immediate v_statement;
              DBMS_OUTPUT.PUT_LINE('Name='||v_name||' ID='||v_id||' PW='||v_pwd||' AC='||v_acct);          
    END LOOP;
    CLOSE get_schemas;
    END;
    /

    Duplicate post.
    When I run this script nothing is output to the screen or spooled to a file

  • My touchscreen blacks out while on a call so I can't multitask. If I am on a call and a new call comes in, I can't see who is calling or even think of answering because the screen is blacked out.

    My touchscreen blacks out while on a call so I can't multitask. If I am on a call and a new call comes in, I can't see who is calling or even think of answering because the screen is blacked out.

    Thank you so very much! My husband is in Afghanistan and calls at different times. If I am on a call and can't answer him it could be days before I hear from him again. I never thought to just restart my phone! Duh...this is my first smartphone so I am learning. All day people were calling while I was on the phone but I couldn't answer. Thank GOD none of the calls were my husband because it would break my heart if I missed his call. Thank you again and GOD bless you! Ashley Combahee

  • HT203977 is there any way to restore factory settings on an Iphone 5s that will not connect to Itunes because the phone is locked with a pass code.  Problem is that the screen is completely shattered.

    is there any way to restore factory settings on an Iphone 5s that will not connect to Itunes because the phone is locked with a pass code.  Problem is that the screen is completely shattered.

    If the screen is completely shattered why bother to try and restore the phone?
    Forgot passcode for your iPhone, iPad, or iPod touch, or your device is disabled - Apple Support

  • When i log onto safari the screen is grayed out and i no touch features are functioning

    when i log onto safari the screen is grayed out and i no touch features are functioning

    Try clearing Safari's cache : Settings > Safari > Clear Cache (and Clear History)
    If that doesn't work then try closing Safari completely and then re-open it : from the home screen (i.e. not with Safari 'open' on-screen) double-click the home button to bring up the taskbar, then press and hold any of the apps on the taskbar for a couple of seconds or so until they start shaking, then press the '-' in the top left of the Safari app to close it, and touch any part of the screen above the taskbar so as to stop the shaking and close the taskbar.
    A third option is a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.

Maybe you are looking for