IntelliJ Java IDE
The moose likes Java Micro Edition and the fly likes Input data from a txt file? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Reply Bookmark "Input data from a txt file?" Watch "Input data from a txt file?" New topic
Author

Input data from a txt file?

Huang Qingyan
Greenhorn

Joined: Jan 18, 2002
Posts: 23
Dear experts,
May I know how to read data from a text file(abc.txt) and print it inside a TextBox on a MIDlet?
I have try DataOInputStream and FileInputStream and there is always error.
Can you guys please kindly teach me how to do it?
Thanks alot, Franco
john muchow
Ranch Hand

Joined: Mar 24, 2001
Posts: 49
Here is a simple block of code to read a file
InputStream is = getClass().getResourceAsStream("help.txt");
try
{
StringBuffer sb = new StringBuffer();
int chr, i = 0;
// Read until the end of the stream
while ((chr = is.read()) != -1)
sb.append((char) chr);
return sb.toString();
}
catch (Exception e)
{
System.out.println("Error");
}
In order for this to work, the file ("help.txt") will need to be packaged with the MIDlet in the JAR file.
John
Core J2ME Technology and MIDP
[ January 18, 2002: Message edited by: john muchow ]
 
 
subject: Input data from a txt file?
 
Threads others viewed
how to create a HTTP Client Program for servlet
deleting from a file
parsing
How can I paint a chart in the jsp
can't add database control
MyEclipse, The Clear Choice