I'm trying to read a txt file following this answer but I can't get it to work. It shows this exception:
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
This is the code:
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);
}
}
I think it has to do with the permissions, but I've set these:
javax.microedition.io.Connector.file.read
javax.microedition.io.Connector.file.write
java.io.FilePermission "file://*" "read,write"
Can anyone help me?
Thanks in advance,