我必须使用文件才能工作。前64字节必须是标题。所以我必须先读取64个字节,然后读取到文件结尾。我如何使用J2ME读写文件?如何在第一个64字节之后读取文件的其余部分?
完全读取一个文件是:
FileConnection fconn= (FileConnection) Connector.open(path+fName,Connector.READ);
InputStream is=fconn.openInputStream();
DataInputStream dis = new DataInputStream(is);
int ch;
String str = new String();
while ((ch = dis.read()) != -1)
{
str+=((char)ch);
}
dis.close();
is.close();
并充分写入文件是:
FileConnection fconn= (FileConnection)Connector.open(path+fName,Connector.READ_WRITE);
if(!fconn.exists()){
items.alert=new Alert(" ","Select The Directory",null,AlertType.INFO);
switchDisplayable(items.alert,items.getList());
fconn.create();
}
os = fconn.openDataOutputStream();
fconn.truncate(0);
os.write(text.getBytes());
os.close();
fconn.close();
这是个好主意。谢谢。但是如何在64字节之后写入? – 2011-04-01 16:54:09
编辑更多信息的答案。请接受它,如果你觉得它有用 – 2011-04-01 17:03:14