Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing from a file to a textfield.

Status
Not open for further replies.

jeremytaffy

Technical User
Sep 6, 2001
75
US
I was wondering what the code is to get the text from a file and display it on a text field. I tried some methods I found on the sun site and I couldn't get it to work.
Thanks in advance.
 
try the following

String contents = new String();
String line = new String();

File f = new File("C:\\Temp\\test.html");
FileInputStream fis = new FileInputStream(f);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));

try{
boolean notEnd = true;
while(notEnd)
{
String line = br.readLine();
if(line != null)
{
contents = contents + " " + line;
}
else
{
notEnd = false;
}
}
}catch (EOFException e){}
br.close();
fis.close();

then just set the textbox value equal to contents
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top