Skip to Content
author's profile photo Former Member
Former Member

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

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!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Dec 17, 2008 at 08:52 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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());
      		}
      

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.