Results 1 to 1 of 1
- 03-08-2009, 12:26 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 3
- Rep Power
- 0
Help me!!!!!!!! Problem with Code!!
I can see the result..
I want to see the this result.
ID. No. In Stock Price
------- -------- ------
1001 476 $28.35
1002 240 $32.56
import java.io.IOException;
import java.io.RandomAccessFile;
public class Raf {
private static class Record{
private final double price;
private final int id;
private final int stock;
public Record(int id, int stock, double price){
this.id = id;
this.stock = stock;
this.price = price;
}
public void pack(int n, int offset, byte[] array){
array[offset + 0] = (byte)(n & 0xff);
array[offset + 1] = (byte)((n >> 8) & 0xff);
array[offset + 2] = (byte)((n >> 16) & 0xff);
array[offset + 3] = (byte)((n >> 24) & 0xff);
}
public void pack(double n, int offset, byte[] array){
long bytes = Double.doubleToRawLongBits(n);
pack((int) (bytes & 0xffffffff), offset, array);
pack((int) ((bytes >> 32) & 0xffffffff), offset + 4, array);
}
public byte[] getBytes() {
byte[] record = new byte[16];
pack(id, 0, record);
pack(stock, 4, record);
pack(price, 8, record);
return record;
}
}
private static final int RECORD_SIZE = 16;
private static final int N_RECORDS = 1024;
public static void main(String[] args) throws IOException {
RandomAccessFile raf = new RandomAccessFile(args[0], "rw");
try{
raf.seek(RECORD_SIZE * N_RECORDS);
raf.seek(0);
raf.write(new Record(1001, 476, 28.35).getBytes());
raf.write(new Record(1002, 240, 32.56).getBytes());
} finally {
raf.close();
}
}
}
Similar Threads
-
Problem my code..
By Miyaki in forum New To JavaReplies: 3Last Post: 03-09-2009, 12:36 AM -
Problem with code
By jvasilj1 in forum New To JavaReplies: 5Last Post: 02-02-2008, 08:34 AM -
Problem with code
By oregon in forum New To JavaReplies: 3Last Post: 08-05-2007, 05:57 PM -
Problem with zero in my code
By fernando in forum New To JavaReplies: 1Last Post: 08-05-2007, 06:39 AM -
Problem with my first code
By paul in forum New To JavaReplies: 2Last Post: 07-26-2007, 04:09 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks