how to read text file

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

how to read text file

Postby logtoavi » Fri Dec 19, 2008 6:21 am

how can I read a text file?
Thanks in advance :)
Thanks and Regards
Avishek Kumar
logtoavi
Freshman
Freshman
 
Posts: 9
Joined: Wed Dec 17, 2008 11:30 am
Location: Noida

Top

Postby logtoavi » Fri Dec 19, 2008 8:10 am

this is my method for reading .txt file and i am calling this file like
String about = readTextFile(r.getString(R.drawable.about));

public String readTextFile(String s)
{
try
{
FileInputStream fIn = new FileInputStream(s);

// Read file with UTF-8
InputStreamReader isr = new InputStreamReader(fIn,"UTF-8");

char[] inputBuffer = new char[255];

isr.read(inputBuffer);
String readString = new String(inputBuffer);

return readString;
} catch (Exception e) {
return e.toString();
}
}

now I am getting exception java.io.FileNotFoundException
Thanks and Regards
Avishek Kumar
logtoavi
Freshman
Freshman
 
Posts: 9
Joined: Wed Dec 17, 2008 11:30 am
Location: Noida

Postby MrSnowflake » Fri Dec 19, 2008 11:51 am

you can use these:
Context.openFileInput(String name)
Context.openFileOutput(String name, int mode)
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby logtoavi » Fri Dec 19, 2008 2:34 pm

Now I am getting another exception

FileNotFoundException at /data/data/demo.demo/files/about
Thanks and Regards
Avishek Kumar
logtoavi
Freshman
Freshman
 
Posts: 9
Joined: Wed Dec 17, 2008 11:30 am
Location: Noida

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests