在 BlackBerry 上使用流保存和读取文件
参数“address”是字符串“CepVizyonVersionFile”,在 Connector.openDataInputStream(address)
之后,程序会抛出异常并显示消息:
网址中没有“:”。
地址应该采用什么格式?
public void saveLocal(String fileString, String address) {
try {
DataOutputStream fos = Connector.openDataOutputStream(address); //openFileOutput(address);
fos.write(fileString.getBytes());
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String readLocal(String address, int lenght) {
byte[] buffer = new byte[lenght];
byte[] buffer2;
String str = new String();
try {
DataInputStream fis = Connector.openDataInputStream(address);
int lnght = fis.read(buffer);
buffer2 = new byte[lnght];
fis.close();
for (int i = 0; i < lnght; i++)
buffer2[i] = buffer[i];
str = new String(buffer2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
Argument 'address' is the string "CepVizyonVersionFile", and after Connector.openDataInputStream(address)
the program throws an exception with message:
no ' : ' in URL.
What format should address be in?
public void saveLocal(String fileString, String address) {
try {
DataOutputStream fos = Connector.openDataOutputStream(address); //openFileOutput(address);
fos.write(fileString.getBytes());
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public String readLocal(String address, int lenght) {
byte[] buffer = new byte[lenght];
byte[] buffer2;
String str = new String();
try {
DataInputStream fis = Connector.openDataInputStream(address);
int lnght = fis.read(buffer);
buffer2 = new byte[lnght];
fis.close();
for (int i = 0; i < lnght; i++)
buffer2[i] = buffer[i];
str = new String(buffer2);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你把你的文件放在哪里?
如果它在媒体卡上,你的地址应该是这样的:“file:///SDCard/”+你的文件名。
Where do you put your file?
If it is on the media card, your address should be like this: "file:///SDCard/"+yourfilename.
Connector 的 BlackBerry API 文档格式说明:
并且还列出了支持的方案:
由于您需要文件,因此需要查看 javax.microedition.io.file
The BlackBerry API documentation for Connector has an explanation of the format:
and the supported schemes are listed as well:
Since you want a file, you'll need to take a look at the package documentation for javax.microedition.io.file