Why?
It may be just a piece of cake for you and it may have many flaws. Anyway, here is my coding.
Code:
try {
fileconnection=(FileConnection)Connector.open("file:///root1"); //place the file you want to read here
InputStream is = fileconnection.openInputStream();
StringBuffer sb = new StringBuffer();
int chr, i = 0;
// Read until the end of the stream
while ((chr = is.read()) != -1)
sb.append((char) chr);
//System.out.println(sb.toString());
Alert alert=new Alert("",sb.toString(),null,AlertType.INFO);
SecondTestFileMIDlet.secondtestfilemidlet.display.setCurrent(alert);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Code:
FileConnection connection = (FileConnection) Connector.open(
"file:///root1/read/tree.png");
InputStream iStrm = connection.openInputStream();
Image im = null;
ImageItem imageitem;
byte imageData[]=new byte[2500];
ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
int ch;
while ((ch = iStrm.read()) != -1)
bStrm.write(ch);
imageData = bStrm.toByteArray();
bStrm.close();
im = Image.createImage(imageData, 0, imageData.length);
imageitem=new ImageItem("",im,1,"");
append(imageitem);