<div></div> reads .txt file

I need a way to make a div on my html page to read an external txt file.
I found loads of solutions using Java but nothing seems to work.

help :(
LVL 1
zahimezherAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nenad RajsicCommented:
try this:
<iframe name="FRAME1" src="robots.txt" width="350" height="360" frameborder="0" ></iframe>
zahimezherAuthor Commented:
i cant use iframe. it has to be a div. i have no idea why but the team leader wants a div :S
StealthyDevCommented:
what is the server script you are using? VB/Java?
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

zahimezherAuthor Commented:
java
StealthyDevCommented:
Try with the code attached.

<%@page import="java.io.*"%>

<%
	BufferedReader input = new BufferedReader(new FileReader("TestFile.txt"));
	String line = "";
	while ((line = input.readLine()) != null) {
		out.println(line);
	}
	input.close();
%> 

Open in new window

StealthyDevCommented:
Please find the updated code into div tag:

<%@page import="java.io.*"%>

<%
	BufferedReader input = new BufferedReader(new FileReader("TestFile.txt"));
	String line = "", fullFile = "";
	while ((line = input.readLine()) != null) {
		//out.println(line);
		fullFile += line + "<BR>";
	}
	out.println("<div>" + fullFile + "</div>");
	input.close();
%> 

Open in new window

zahimezherAuthor Commented:
didnt work on my machine so i tried uploading. the code showed on the html page.
my server is php based
StealthyDevCommented:
Then use this?

$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, 5);
fclose($fh);
echo $theData;

Open in new window

StealthyDevCommented:
This should work perfectly.

<div>
<?php
$fh = fopen("myfile.txt", "r");

$file = file_get_contents("myfile.txt");
echo $file;
?>
</div>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JScript

From novice to tech pro — start learning today.