java怎么读取c++保存的结构体的文件,我用bufferReader读取的内容都不对
c++的结构体
struct TestS
{
int nID;
int nSize;
char szTest[32];
}; test.nID=100;
test.nSize=1000;
strcpy(test.szTest,"1234567890中国!");
/**
* 从文件中读取文本
*/
public void readFromFile(String file) {
try {
String str="";
BufferedReader bre = null;
bre = new BufferedReader(new FileReader(file));//此时获取到的bre就是整个文件的缓存流
while ((str = bre.readLine())!= null) // 判断最后一行不存在,为空结束循环
{
System.out.println(str);
}
bre.close();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
c++的结构体
struct TestS
{
int nID;
int nSize;
char szTest[32];
}; test.nID=100;
test.nSize=1000;
strcpy(test.szTest,"1234567890中国!");
/**
* 从文件中读取文本
*/
public void readFromFile(String file) {
try {
String str="";
BufferedReader bre = null;
bre = new BufferedReader(new FileReader(file));//此时获取到的bre就是整个文件的缓存流
while ((str = bre.readLine())!= null) // 判断最后一行不存在,为空结束循环
{
System.out.println(str);
}
bre.close();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String readFile(String path, String encoding) {
File file = new File(path);
String fileContent = null;
try {
if(file.exists()) {
fileContent = FileUtils.readFileToString(file, encoding);
}
} catch (IOException e) {
e.printStackTrace();
}
return fileContent;
}