我最近想要把一个个java的小程序改写成C#写的,不知道java中的FileChannel和MappedByteBuffer在C#中应该用什么来替代
程序片段如下:
FileChannel fc = null;
MappedByteBuffer byteBuffer = null;
int size = 0;
int pointer = 0;
int readpointer = 0;
String root = "";
String fname = ""; public long init(String root, String fname, byte site, byte gameType, byte numberOfSeats, byte cWeek) {
return init(root, fname + site + "_" + gameType + "_" + numberOfSeats + "_w" + cWeek + ".hhex");
}
// opens DB for usage, returns the size of the DB
public long init(String root, String fullname) {
try {
fc = new FileInputStream(root + fullname).getChannel();
long tsize = fc.size();
if (tsize >= Integer.MAX_VALUE) {
System.out.println("ERROR: DB size is larger than Integer.MAXVALUE, truncated to " + Integer.MAX_VALUE);
//tsize = Integer.MAX_VALUE - 1;
tsize = Integer.MAX_VALUE-1;
}
byteBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, tsize);
size = byteBuffer.capacity();
//System.out.println("DEBUG: Size of opened DB is " + size + " bytes.");
pointer = 0;
readpointer = 0;
this.root = root;
this.fname = fname;
} catch (FileNotFoundException fn) {
return 0;
} catch (Exception e) {
e.printStackTrace(); // most probably file does not exist
return 0;
}
return size;
}主要是我不太清楚MappedByteBuffer这个在c#中用什么替换?fc = new FileInputStream(root + fullname).getChannel();
byteBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, tsize);
程序片段如下:
FileChannel fc = null;
MappedByteBuffer byteBuffer = null;
int size = 0;
int pointer = 0;
int readpointer = 0;
String root = "";
String fname = ""; public long init(String root, String fname, byte site, byte gameType, byte numberOfSeats, byte cWeek) {
return init(root, fname + site + "_" + gameType + "_" + numberOfSeats + "_w" + cWeek + ".hhex");
}
// opens DB for usage, returns the size of the DB
public long init(String root, String fullname) {
try {
fc = new FileInputStream(root + fullname).getChannel();
long tsize = fc.size();
if (tsize >= Integer.MAX_VALUE) {
System.out.println("ERROR: DB size is larger than Integer.MAXVALUE, truncated to " + Integer.MAX_VALUE);
//tsize = Integer.MAX_VALUE - 1;
tsize = Integer.MAX_VALUE-1;
}
byteBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, tsize);
size = byteBuffer.capacity();
//System.out.println("DEBUG: Size of opened DB is " + size + " bytes.");
pointer = 0;
readpointer = 0;
this.root = root;
this.fname = fname;
} catch (FileNotFoundException fn) {
return 0;
} catch (Exception e) {
e.printStackTrace(); // most probably file does not exist
return 0;
}
return size;
}主要是我不太清楚MappedByteBuffer这个在c#中用什么替换?fc = new FileInputStream(root + fullname).getChannel();
byteBuffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, tsize);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货