Hi,
I want to build an application in which i've to read text file.Can any one help me regarding this.Is there any API/method/site for reference to do so?(with actual example's source code.)
Sachin Warang.
Hi,
I want to build an application in which i've to read text file.Can any one help me regarding this.Is there any API/method/site for reference to do so?(with actual example's source code.)
Sachin Warang.
Here are some links that might be of some interest to you.
http://developers.sun.com/techtopics...ork/index.html
http://developers.sun.com/techtopics...ion/index.html
http://developers.sun.com/techtopics...icles/network/
Regards
Gopal
Hi
I develop an mobile application. which need to read text file.
i am faceing one problem. when i run the application in my desktop. i have use the file path, file:///root1/myText.txt, it is working in my desktop..
but when i run this application in mobile the application is not getting the path.. would you plz help me.... how i need to show the path.. like for mobile Nokia N97, or N70.. or any common path for all the mobiles
Hi Sachin.
I thing the following coul help you..
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ReadFile extends MIDlet implements CommandListener{
private Display display;
private Form form;
private Command read, exit;
private Alert alert;
public ReadFile(){
display = Display.getDisplay(this);
read = new Command("Read", Command.SCREEN, 1);
exit = new Command("Exit", Command.EXIT, 1);
form = new Form("Read File");
form.addCommand(exit);
form.addCommand(read);
form.setCommandListener(this);
}
public void startApp(){
display.setCurrent(form);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void commandAction(Command c, Displayable s){
String label = c.getLabel();
if (label.equals("Read")){
String string = file();
if (string != null){
alert = new Alert("Reading", string, null, null);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, form);
}
} else if (label.equals("Exit")){
destroyApp(false);
}
}
private String file(){
InputStream is = getClass().getResourceAsStream("help.txt");
StringBuffer sb = new StringBuffer();
try{
int chars, i = 0;
while ((chars = is.read()) != -1){
sb.append((char) chars);
}
return sb.toString();
}catch (Exception e){}
return null;
}
}
This should be used for path : file:///C:/Data/+
Also see the File connection API document for reference. Search in the wiki Java .
Best regards,
hi frnd,
your application will not work on mobile application if you hard coded root name of filesystem.In Nokia and sony phone you will find C: and EMemory card).and In samsung and LG also have different.so dont hard code value.first find root of mobile.by using FileSystemRegistry.listRoots().
Ajay Prajapati
Mobile Software Developer
Mumbai,India
This is my code to read an image. simply you can change it to read text message:
PHP Code:public Image readFile(String path)//test===============
{
try
{
FileConnection fc = (FileConnection)Connector.open(path, Connector.READ);
if(!fc.exists()) {
System.out.println("File doesn't exist!");
}
else
{
int size = (int)fc.fileSize();
InputStream is = fc.openInputStream();
byte bytes[] = new byte[size];
is.read(bytes, 0, size);
image = Image.createImage(bytes, 0, size);
}
} catch (IOException ioe) {
System.out.println("IOException: "+ioe.getMessage());
} catch (IllegalArgumentException iae) {
System.out.println("IllegalArgumentException: "+iae.getMessage());
}
return image;
}