The class java.io.FileReader
not found in Java ME.
I need this in order to get the file and then parse it with an xml parser.
Anyone know any alternatives for this class?
*added using CLDC profile. The xml file to be read is in the JAR.
The class java.io.FileReader
not found in Java ME.
I need this in order to get the file and then parse it with an xml parser.
Anyone know any alternatives for this class?
*added using CLDC profile. The xml file to be read is in the JAR.
That's because Java ME provides only a limited subset of the java.io
package. You need to use the java.microedition.io
package instead.
For actual file I/O you'll need to use the FileConnection
class provided by JSR-75.
What Java ME profile are you using? The CLDC does not support the concept of files at all.
In general, FileReader
is nothing but a convenience class that wraps an InputStreamReader
areound a FileInputStream
. It's also very broken because it does not allow specifying the encoding, and should therefore almost never be used.
It would be especially wrong to use it to read XML because proper XML data specifies its encoding, and a proper XML parser will handle that, so you really should pass binary data to the XML parser.
So if you're on the CDC profile, just use a FileInputStream
directly.
Hi, the question is a bit ambiguous. I think Joachim's answer might be only partial if you are trying to read a local file. I'm certainly not sure though.
If the file is stored as a resource in your JAR, you can access it through the getResourceAsStream method in Class
.
If the file is a local file on the file system and if I recall correctly, you need JSR-75 support. Over at Sun's developer page there is an introduction to JSR 75 and the fileconnection API.