//通过chr函数将一个byte转换成字符
procedure TForm1.Button1Click(Sender: TObject);
Const
b : Array[0..88] of Byte = (0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 128, 152, 255, 255, 5, 128, 84, 40, 9, 1, 0, 255, 3, 255, 255, 255, 255, 255, 16, 56, 59, 174, 113, 4, 220, 81, 134, 4, 208, 91, 136, 4, 92, 97, 116, 4, 80, 102, 4, 36, 112, 170, 68, 113, 142, 4, 93, 125, 132, 4, 28, 127, 159, 164, 143, 4, 162, 69, 176, 102, 8, 60, 188, 94, 4, 76, 190, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
Var
i, j : Integer;
sFName : OleVariant;
fLog : TextFile;
begin
sFName := 'C:/Bin.dat';
AssignFile(fLog, sFName);
ReWrite(fLog);
//
for i := 0 To Length(b)-1 Do
begin
Write(fLog, Chr(b
));
end;
//
CloseFile(fLog);
end;
//下面是Java程序
import java.io.*;
public class TestByte{
public static void main(String[] a){
LoadMyFile();
}
public static void LoadMyFile(){
int len = 0, i=0;
byte data[] = new byte [1024];
FileInputStream fis;
try{
fis = new FileInputStream("C://Bin.dat"
}catch(FileNotFoundException e){
System.out.println("文件打开失败:"
+ e.getMessage());
return;
}
try{
while (true){
len = fis.read(data, 0, 1024);
if (len == -1) break;
for (i=1
i<=len
i++){
System.out.print(data[i-1] + ", "
if ((i % 10)==0) System.out.println();
}
}
}catch(IOException e){return;}
try{
fis.close();
}catch(IOException e){return;}
return
}
}
//运行后显示结果(java中byte范围位 -128 ~ 127)
0, 0, 0, 0, 0, 0, 0, 0, 0, 42,
0, -128, -104, -1, -1, 5, -128, 84, 40, 9,
1, 0, -1, 3, -1, -1, -1, -1, -1, 16,
56, 59, -82, 113, 4, -36, 81, -122, 4, -48,
91, -120, 4, 92, 97, 116, 4, 80, 102, 4,
36, 112, -86, 68, 113, -114, 4, 93, 125, -124,
4, 28, 127, -97, -92, -113, 4, -94, 69, -80,
102, 8, 60, -68, 94, 4, 76, -66, 116, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,