2013年9月20日星期五

Neighborhoods : c language to open the saved file java problem

 This post last edited by the fieldisme on 2013-09-18 08:28:36

struct Data//数据结构
{wchar_t a[100];
 int b ;
 wchar_t c[20];
};
//保存到文件
Data a;file f;
..........
f.Write(&a,sizeof(Data);

The above is the general way to save a file
read the following in java

class Data
{byte a[]=new byte[200];
 byte b[]=new byte[4];
 byte c[]=new byte[40];
};
//以下代码在窗口(activity)的onCreate事件中
Data data=new Data();
InputStream filestream;
filestream=getResources().openRawResource(R.raw.info);
filestream.read(data.a);
filestream.read(data.b);
filestream.read(data.c);
filestream.close();
//以下把byte转换成字符,得到的结果不正确,如果换Data的成员变量a或b数组数减少1,勉强正确,
//但结束符之后的仍然被显示
String res = EncodingUtils.getString(data.c, "UNICODE");
//以下取出把b转换成int型,结果怎么都得不到正确值
int k=(((int)data.b[0]) << 24) + (((int)data.b[1]) << 16) + (((int)data.b[2]) << 8) + data.b[3]
please greatly pointing in java how to read the correct value, I use Eclipse3.71, Andrews programming
------ Solution ---------- ----------------------------------
why not json format or xml
--- --- Solution --------------------------------------------
Why does it have to do with java
When you use filestream mosaic character stream can try, arguably java read the file , then it should be possible
------ Solution ------ --------------------------------------
suggest you use C + + to save the file, do not write directly to the structure , the basic data is written into a try. C + + in the file structure of a data structure , and JAVA object data stored in the file structure , may not be the same . This has led to an object you use to read JAVA reads C + + structures , problems can arise.
------ Solution ---------------------------------------- ----
json is really good stuff
------ Solution -------------------------- ------------------
regardless of what language to use to write the file , as long as you write when stored as text in any language can be easily read out .
------ Solution ---------------------------------------- ----
in c + + to write files when adding a program to write to a file using c + + compiled a do json xml will do to solve
------ Solution ------------------------------------------ -

understand JSON does not matter , C written to the file structure when not writing , but the basic data structure in a specific order according to a stored file, and then in java read in the same order on the line .
------ Solution ---------------------------------------- ----
do not directly write data, because you do not know c in the end is how to store the data structure struct ,

really want to do this job , you can use a tool such UltrulEdit hex code to see the file , the data storage structure under study first
------ For reference only --------- ------------------------------

java I would not , the data has been handled using c + + , and change the data structure indeed affect the whole body, very troublesome
------ For reference only ----------------------- ----------------

so root you the truth, my data is generated dynamically, to go through a lot of very complicated operation process to get to me java level is 0 , simply can not do , the data is ready, just need to show up on the phone on the line, so the java able to read correctly on the line, but the right side for me to read all very difficult to do
------ For reference only ---------------------------------------
fact data is the interface information different customers require different interface displayed on the phone , the number of buttons may be different , the number of windows are different, different background , different display text , the information in this info file , info file is generated by an interface design software generated , this software is written using c + +
------ For reference only ------------------------------- --------
thanks for your enthusiastic response , json heard estimated data is a special combination of it, the future will be to get to know , but now I am most anxious that my in java how data read out is a binary file , my data has to be, to change the way data is stored , then, too much trouble , can I write to a file so that there is no way to read out the java do
- ----- For reference only ---------------------------------------
Thank you for your answer , I have resolved, because:
1. strings , C + + direct deposit to save UNICODE string to the corresponding code value , java converted by byte string , byte array of the first two bytes are signs, c language data is not due flag that causes a problem, the logo is the first byte is -1 , the second byte is -2 , I will read out the data before the plus sign and then convert it.
2.int type , C + + and java stored in the high byte and low byte int is just the opposite , for example 5 , in C + +, saved as 0005, java in memory of 5000 , which in turn will be able to , caused by the other , yet space research

没有评论:

发表评论