plook
IS-IT--Management
- Apr 1, 2000
- 33
Hi there,
I hope everyone here is doing great. I am looking for some hints.
In the class I am making, I have the following code :
if(counter==3)
{
WriteIntByByte(some_integer);
System.out.println("test");
}
And WriteIntByByte is this :
static void WriteIntByByte( int x ) throws IOException
{
int [] mask = { 0xff000000, 0x00ff0000, 0x0000ff00,0x000000ff };
for (int i = 0; i<4; i++) ous.write((mask & x) >>> (24 - 8*i));
}
All what WriteIntByByte does is to take 4 bytes and make one Integer using bitwise operators. Then write it using BufferedOutputStream.
When I do like this :
if(counter==3)
{
WriteIntByByte(some_integer);
System.out.println("test");
}
//That displays "test" on the screen, but does not write anything
When I try this :
WriteIntByByte(some_integer);
if(counter==3)
{
System.out.println("test");
}
//That displays "test" and write to the file.
So, trying to write inside the if does not work, while outside does. Ok fine, so I tried
if(counter>0)
{
WriteIntByByte(some_integer);
System.out.println("test");
}
//That works, prints "test" and write to the file.
But...
if(counter>1)
{
WriteIntByByte(some_integer);
System.out.println("test");
}
//That does not work: only prints "test".
Maybe it's because I don't have a lot of experience in Java, but that seems weird to me. I mean, sometimes it does into the if, runs the second statement, but not the first one.
Any suggestion or help would be greatly appreciated.
Thank you in advance.
Dominic
I hope everyone here is doing great. I am looking for some hints.
In the class I am making, I have the following code :
if(counter==3)
{
WriteIntByByte(some_integer);
System.out.println("test");
}
And WriteIntByByte is this :
static void WriteIntByByte( int x ) throws IOException
{
int [] mask = { 0xff000000, 0x00ff0000, 0x0000ff00,0x000000ff };
for (int i = 0; i<4; i++) ous.write((mask & x) >>> (24 - 8*i));
}
All what WriteIntByByte does is to take 4 bytes and make one Integer using bitwise operators. Then write it using BufferedOutputStream.
When I do like this :
if(counter==3)
{
WriteIntByByte(some_integer);
System.out.println("test");
}
//That displays "test" on the screen, but does not write anything
When I try this :
WriteIntByByte(some_integer);
if(counter==3)
{
System.out.println("test");
}
//That displays "test" and write to the file.
So, trying to write inside the if does not work, while outside does. Ok fine, so I tried
if(counter>0)
{
WriteIntByByte(some_integer);
System.out.println("test");
}
//That works, prints "test" and write to the file.
But...
if(counter>1)
{
WriteIntByByte(some_integer);
System.out.println("test");
}
//That does not work: only prints "test".
Maybe it's because I don't have a lot of experience in Java, but that seems weird to me. I mean, sometimes it does into the if, runs the second statement, but not the first one.
Any suggestion or help would be greatly appreciated.
Thank you in advance.
Dominic