cancel
Showing results for 
Search instead for 
Did you mean: 

Read a text file and put the text in a TextEdit UI

Former Member
0 Kudos

I have found code sample for reading file inside webdynpro, but I can't manage to make it works with a text file on the web (ex.: "http:/.../file.txt").

Can someone post the exact code needed for that?

Thanks!

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Have a look at class java.net.URL and method openStream().

http://java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html

Armin

Former Member
0 Kudos

Well, I expected a code sample that works. I guess I will start a new bunch of tests instead!

Former Member
0 Kudos

Read the text file from the URL, store its content in a context attribute of type "string", bind the TextEdit.value property to that context attribute. That's it.

Armin

Former Member
0 Kudos

Com'on.. you only repeated my question, do you really expect points for that? hehe

Former Member
0 Kudos

I don't help people here in SDN to earn points and I never asked for them. And I expect that this is a forum for professional programmers and not for people who expect solutions for their homework.

Armin

Former Member
0 Kudos

Hope this post will help people doing their homeworks...


		StringBuffer tmpBuffer = new StringBuffer();

		try {

			URL url = new URL("http://.../test.txt");
			URLConnection urlconnection = url.openConnection();
			long l = urlconnection.getContentLength();
			tmpBuffer.append("Content Length = " + l);
			BufferedReader in =
				new BufferedReader(new InputStreamReader(url.openStream()));

			String line;

			while ((line = in.readLine()) != null) {
				tmpBuffer.append("\n" + line);
			}
			in.close();
		} catch (Exception e) {
			//System.out.println(e.toString());
		}

		if (tmpBuffer != null) {
			wdContext.currentContextElement().setZoneMessage(
				tmpBuffer.toString());
		}