<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FJ2ME%2FStreamConnection</id>
		<title>Java Tutorial/J2ME/StreamConnection - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FJ2ME%2FStreamConnection"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/J2ME/StreamConnection&amp;action=history"/>
		<updated>2026-04-07T14:43:57Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/J2ME/StreamConnection&amp;diff=4128&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/J2ME/StreamConnection&amp;diff=4128&amp;oldid=prev"/>
				<updated>2010-06-01T05:00:04Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:00, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/J2ME/StreamConnection&amp;diff=4127&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/J2ME/StreamConnection&amp;diff=4127&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  Load text file from a URL ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
/* License&lt;br /&gt;
 * &lt;br /&gt;
 * Copyright 1994-2004 Sun Microsystems, Inc. All Rights Reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without&lt;br /&gt;
 * modification, are permitted provided that the following conditions&lt;br /&gt;
 * are met:&lt;br /&gt;
 *  &lt;br /&gt;
 *  * Redistribution of source code must retain the above copyright notice,&lt;br /&gt;
 *      this list of conditions and the following disclaimer.&lt;br /&gt;
 * &lt;br /&gt;
 *  * Redistribution in binary form must reproduce the above copyright notice,&lt;br /&gt;
 *      this list of conditions and the following disclaimer in the&lt;br /&gt;
 *      documentation and/or other materials provided with the distribution.&lt;br /&gt;
 * &lt;br /&gt;
 * Neither the name of Sun Microsystems, Inc. or the names of contributors&lt;br /&gt;
 * may be used to endorse or promote products derived from this software&lt;br /&gt;
 * without specific prior written permission.&lt;br /&gt;
 *  &lt;br /&gt;
 * This software is provided &amp;quot;AS IS,&amp;quot; without a warranty of any kind. ALL&lt;br /&gt;
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING&lt;br /&gt;
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE&lt;br /&gt;
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. (&amp;quot;SUN&amp;quot;)&lt;br /&gt;
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE&lt;br /&gt;
 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS&lt;br /&gt;
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST&lt;br /&gt;
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,&lt;br /&gt;
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY&lt;br /&gt;
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,&lt;br /&gt;
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.&lt;br /&gt;
 *  &lt;br /&gt;
 * You acknowledge that this software is not designed, licensed or intended&lt;br /&gt;
 * for use in the design, construction, operation or maintenance of any&lt;br /&gt;
 * nuclear facility. &lt;br /&gt;
 */&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import javax.microedition.io.Connector;&lt;br /&gt;
import javax.microedition.io.StreamConnection;&lt;br /&gt;
import javax.microedition.lcdui.Display;&lt;br /&gt;
import javax.microedition.lcdui.TextBox;&lt;br /&gt;
import javax.microedition.midlet.MIDlet;&lt;br /&gt;
public class J2MEFirstExample extends MIDlet {&lt;br /&gt;
  private Display display;&lt;br /&gt;
  String url = &amp;quot;http://www.y.ru/hello.txt&amp;quot;;&lt;br /&gt;
  public J2MEFirstExample() {&lt;br /&gt;
    display = Display.getDisplay(this);&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * This will be invoked when we start the MIDlet&lt;br /&gt;
   */&lt;br /&gt;
  public void startApp() {&lt;br /&gt;
    try {&lt;br /&gt;
      getViaStreamConnection(url);&lt;br /&gt;
    } catch (IOException e) {&lt;br /&gt;
      e.printStackTrace();&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  public void pauseApp() {&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * Destroy must cleanup everything.&lt;br /&gt;
   */&lt;br /&gt;
  public void destroyApp(boolean unconditional) {&lt;br /&gt;
  }&lt;br /&gt;
  /**&lt;br /&gt;
   * read url via stream connection&lt;br /&gt;
   */&lt;br /&gt;
  void getViaStreamConnection(String url) throws IOException {&lt;br /&gt;
    StreamConnection c = null;&lt;br /&gt;
    InputStream s = null;&lt;br /&gt;
    StringBuffer b = new StringBuffer();&lt;br /&gt;
    TextBox t = null;&lt;br /&gt;
    try {&lt;br /&gt;
      c = (StreamConnection) Connector.open(url);&lt;br /&gt;
      s = c.openInputStream();&lt;br /&gt;
      int ch;&lt;br /&gt;
      while ((ch = s.read()) != -1) {&lt;br /&gt;
        b.append((char) ch);&lt;br /&gt;
      }&lt;br /&gt;
      System.out.println(b.toString());&lt;br /&gt;
      t = new TextBox(&amp;quot;hello....&amp;quot;, b.toString(), 1024, 0);&lt;br /&gt;
    } finally {&lt;br /&gt;
      if (s != null) {&lt;br /&gt;
        s.close();&lt;br /&gt;
      }&lt;br /&gt;
      if (c != null) {&lt;br /&gt;
        c.close();&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    display.setCurrent(t);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Read from URL ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.IOException;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import javax.microedition.io.Connector;&lt;br /&gt;
import javax.microedition.io.StreamConnection;&lt;br /&gt;
import javax.microedition.lcdui.Alert;&lt;br /&gt;
import javax.microedition.lcdui.AlertType;&lt;br /&gt;
import javax.microedition.lcdui.rumand;&lt;br /&gt;
import javax.microedition.lcdui.rumandListener;&lt;br /&gt;
import javax.microedition.lcdui.Display;&lt;br /&gt;
import javax.microedition.lcdui.Displayable;&lt;br /&gt;
import javax.microedition.lcdui.Form;&lt;br /&gt;
import javax.microedition.lcdui.StringItem;&lt;br /&gt;
import javax.microedition.midlet.MIDlet;&lt;br /&gt;
import javax.microedition.midlet.MIDletStateChangeException;&lt;br /&gt;
public class J2MEHttpExample extends MIDlet implements CommandListener {&lt;br /&gt;
  private Command exit= new Command(&amp;quot;Exit&amp;quot;, Command.EXIT, 1), start= new Command(&amp;quot;Start&amp;quot;, Command.EXIT, 1);&lt;br /&gt;
  private Display display;&lt;br /&gt;
  private Form form = new Form(&amp;quot;Customer Ranking&amp;quot;);&lt;br /&gt;
  public J2MEHttpExample() {&lt;br /&gt;
    display = Display.getDisplay(this);&lt;br /&gt;
    form.addCommand(exit);&lt;br /&gt;
    form.addCommand(start);&lt;br /&gt;
    form.setCommandListener(this);&lt;br /&gt;
  }&lt;br /&gt;
  public void startApp() throws MIDletStateChangeException {&lt;br /&gt;
    display.setCurrent(form);&lt;br /&gt;
  }&lt;br /&gt;
  public void pauseApp() {&lt;br /&gt;
  }&lt;br /&gt;
  public void destroyApp(boolean unconditional) {&lt;br /&gt;
  }&lt;br /&gt;
  public void commandAction(Command command, Displayable displayable) {&lt;br /&gt;
    if (command == exit) {&lt;br /&gt;
      destroyApp(false);&lt;br /&gt;
      notifyDestroyed();&lt;br /&gt;
    } else if (command == start) {&lt;br /&gt;
      StreamConnection connection = null;&lt;br /&gt;
      InputStream in = null;&lt;br /&gt;
      StringBuffer buffer = new StringBuffer();&lt;br /&gt;
      try {&lt;br /&gt;
        connection = (StreamConnection) Connector.open(&amp;quot;http://www.a.ru/&amp;quot;);&lt;br /&gt;
        in = connection.openInputStream();&lt;br /&gt;
        int ch;&lt;br /&gt;
        while ((ch = in.read()) != -1) {&lt;br /&gt;
          if (ch != &amp;quot;\n&amp;quot;) {&lt;br /&gt;
            buffer.append((char) ch);&lt;br /&gt;
          } else {&lt;br /&gt;
            String line = new String(buffer.toString());&lt;br /&gt;
            if (line.equals(&amp;quot;o&amp;quot;)) {&lt;br /&gt;
              int position = line.indexOf(&amp;quot;alt=&amp;quot;);&lt;br /&gt;
              Alert alert = new Alert(&amp;quot;Alert&amp;quot;, line.substring(position + 5, position + 8), null,&lt;br /&gt;
                  null);&lt;br /&gt;
              alert.setTimeout(Alert.FOREVER);&lt;br /&gt;
              alert.setType(AlertType.ERROR);&lt;br /&gt;
              display.setCurrent(alert);&lt;br /&gt;
            }&lt;br /&gt;
            buffer = new StringBuffer();&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      } catch (IOException error) {&lt;br /&gt;
        Alert alert = new Alert(&amp;quot;Error&amp;quot;, &amp;quot;Cannot connect&amp;quot;, null, null);&lt;br /&gt;
        alert.setTimeout(Alert.FOREVER);&lt;br /&gt;
        alert.setType(AlertType.ERROR);&lt;br /&gt;
        display.setCurrent(alert);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>