1 import java.io.BufferedReader; 2 import java.io.IOException; 3 import java.io.InputStream; 4 import java.io.InputStreamReader; 5 import java.net.HttpURLConnection; 6 import java.net.URL; 7 8 import javax.swing.JFrame; 9 import javax.swing.JLabel; 10 import javax.swing.JTextField; 11 12 public class PassWord 13 { 14 static String str; 15 public void CapturePWD() throws Exception 16 { 17 String strURL = "http://www.ishadowsocks.com"; 18 19 URL url = new URL(strURL); 20 21 HttpURLConnection httpCoonn = (HttpURLConnection) url.openConnection(); 22 23 InputStreamReader input = new InputStreamReader(httpCoonn.getInputStream(), "utf-8"); 24 25 BufferedReader bufReader = new BufferedReader(input); 26 27 String line = ""; 28 StringBuilder contentBuf = new StringBuilder(); 29 30 while ((line = bufReader.readLine()) != null) 31 { 32 contentBuf.append(line); 33 } 34 String buf = contentBuf.toString(); 35 36 int beginIx = buf.indexOf("A密码"); 37 int endIx = buf.indexOf("加密方式:aes-256-cfb"); 38 39 str = buf.substring(beginIx, endIx - 29); 40 } 41 42 public static void main(String[] args) throws IOException 43 { 44 try 45 { 46 new PassWord().CapturePWD(); 47 } catch (Exception e) 48 { 49 // TODO Auto-generated catch block 50 e.printStackTrace(); 51 } 52 interFace iF = new interFace(); 53 iF.setVisible(true); 54 55 } 56 57 } 58 59 class interFace extends JFrame 60 { String str = new PassWord().str; 61 private JLabel jLabel; 62 private JTextField jTextField; 63 public interFace() 64 { 65 super(); 66 this.setSize(300, 200); 67 this.getContentPane().setLayout(null); 68 // this.add(getJLabel(),null); 69 70 jTextField = new javax.swing.JTextField(); 71 jTextField.setBounds(96, 49, 160, 20); 72 jTextField.setText(new PassWord().str); 73 this.add(jTextField); 74 75 } 76 // private javax.swing.JLabel getJLabel() { 77 // if(jLabel == null) { 78 // jLabel = new javax.swing.JLabel(); 79 // jLabel.setBounds(96, 49, 160, 20); 80 // jLabel.setText(str); 81 // } 82 // return jLabel; 83 // } 84 }
但是eclipse里面运行没有问题啊!求解,运行时会有这样的提示。。
不知道
坐等。= =
你用什么程序运行的,我用Eclipse运行没错啊
OSX ,Eclipse JavaEE啊。。。所以很奇怪。。。
你没有报错么?
@KicasTec:我用Eclipse运行没报错