- 511 名前:486 mailto:sage [2010/06/14(月) 13:52:34 ]
- わけの分からない動きをします。
//str.substring(i); のコメントを外すと、それまでちゃんと動いてたのが 出力 ho になります。 前の行に戻ってるとしか思えないんですが…。 public class My{ public static void main(String[] args){ URL url = new URL("www.amazon.co.jp/gp/product/4484032058/ref=s9_simh_gw_p14_i2?pf_rd_m=AN1VRQENFRJN5&pf_rd_s=center-1&pf_rd_r=1GH5SJXET02DJCFR2X33&pf_rd_t=101&pf_rd_p=463376736&pf_rd_i=489986"); HttpURLConnection con = (HttpURLConnection)url.openConnection(); InputStreamReader in = new InputStreamReader(con.getInputStream(), Charset.forName("shift-JIS")); StringBuilder sb = new StringBuilder(); while(true){ char[] buf = new char[1024]; int read = in.read(buf); if(read == -1){ System.out.println("ho"); break; } sb.append(buf,0,read); } in.close(); con.disconnect(); String str = sb.toString(); int i = str.lastIndexOf("shoveler-content"); //str.substring(i); System.out.println(str); } }
|

|