Reputation: 39
Is there any equivalent to FileInputStream
in J2ME?
Upvotes: 4
Views: 922
Reputation: 5823
If you are only concerned with files in the JAR file, then have a look at getResourceAsStream method, the device does not need to have JSR 75 to use it.
Upvotes: 1
Reputation: 7685
Agreed, the FileConnection and it's getInputStream method will are the closest you will get to a FileInputStream. Here's a quick tutorial with source code:
http://j2mesamples.blogspot.com/2009/02/file-connection-using-j2me-api-jsr-75.html
You will find more information on this page:
Upvotes: 2
Reputation: 115328
You should use FileConnection from JSR 75. Here is a short example of using file connection for reading file:
public void showFile(String fileName) {
try {
FileConnection fc = (FileConnection)
Connector.open("file:///CFCard/" + fileName);
if(!fc.exists()) {
throw new IOException("File does not exist");
}
InputStream is = fc.openInputStream();
byte b[] = new byte[1024];
int length = is.read(b, 0, 1024);
System.out.println
("Content of "+fileName + ": "+ new String(b, 0, length));
} catch (Exception e) {
}
}
Please take a look here for more info.
Upvotes: 9