1
我試圖讀取此answer後面的txt文件,但我無法使其工作。它顯示了此異常:J2ME異常打開文件:根目錄不可訪問
java.io.IOException: Root is not accessible
- com/sun/io/j2me/file/Protocol..unknown.(), bci=21
- com/sun/io/j2me/file/Protocol..unknown.(), bci=424
- com/sun/io/j2me/file/Protocol..unknown.(), bci=5
- javax/microedition/io/Connector.open(), bci=73
- javax/microedition/io/Connector.open(), bci=6
- javax/microedition/io/Connector.open(), bci=3
這是代碼:
try
{
fileConnection = (FileConnection)Connector.open("file://home//pi//test.txt", Connector.READ_WRITE);
if(fileConnection.exists())
{
int size = (int)fileConnection.fileSize();
is= fileConnection.openInputStream();
byte bytes[] = new byte[size];
is.read(bytes, 0, size);
String str = new String(bytes, 0, size);
System.out.println(size);
}
}
我認爲它有相應的權限,但我已經設置這些:
javax.microedition.io.Connector.file.read
javax.microedition.io.Connector.file.write
java.io.FilePermission "file://*" "read,write"
能
人幫我?
由於提前,
我自己找到了解決方案,路徑不是以'home'開頭,而是以'root1' – cuoka