易截截图软件、单文件、免安装、纯绿色、仅160KB

Java从web服务器下载文件到本地

/*从服务器中下载文件到本地*/
/*url:文件存放在服务器的地址;target:要保存的路径*/
 
public String DownloadFile(String url,String target){
URLConnection con=null;
URL theUrl=null;
try {
theUrl=new URL(url);//建立地址
con = theUrl.openConnection();//打开连接
con.setConnectTimeout(30000);
con.connect();//连接
} catch (MalformedURLException e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e);
return "给定的URL地址有误,请查看";
}
catch (IOException e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e);
return "无法连接到远程机器,请重试!";
}
jLabel5.setText("√");
Process++;
File file = new File(gbl_ParentPath+"/UpdateTemp");
if(file.exists()==false){
file.mkdir();
}
String type = con.getContentType();
if (type != null) {
byte[] buffer = new byte[4 * 1024];
int read;
try {
FileOutputStream os = new FileOutputStream(target);
InputStream in = con.getInputStream();//重定向输入
while ((read = in.read(buffer)) > 0) {//读取输出
os.write(buffer, 0, read);//写入本地文件
}
os.close();
in.close();
jLabel6.setText("√");
Process++;
} catch (FileNotFoundException e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e);
return "所要下载的文件不存在!";
}catch (IOException e) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e);


相关文档:

Java获取请求客户端的真实IP地址

转自 http://blog.csdn.net/foamflower/archive/2009/10/29/4744862.aspx
像移动网关一样,iisforward这个ISAPI过滤器也会对request对象进行再包装,附加一些WLS要用的头信息。这种情况下,直接用request.getRemoteAddr()
是无法取到真正的客户IP的。
实际的iisforward附加头如下:
WL-Proxy-Client-IP=211.161.1.239 ......

JAVA专业术语集

 JAVA专业术语集
API:Java ApplicationProgrammingInterface API(应用程序接口)是事先写好的代码,
        组织到相关包。例如 Applet 和 AWT 包包括建立字体、菜单、按钮的类(CLASS),
        全部的Java API被包含在JavaTM 2 Stan ......

java自定义类


继承:
java只有单继承,不能同时继承多个类
class Animal{}
class Fish extends Aniaml{}
 super.(父类中与子类相同的方法)();//super-特殊的变量,用于访问父类中与子类相同的方法,如下
//父类
class Fish extends animal
{
 void output()
 {
  System.out.println("Fish");
&n ......

Java实现队列操作


import java.util.LinkedList;  
//单向队列  
public class Queue {  
    public Queue() {  
    }  
    private LinkedList list = new LinkedList();  
    public void pu ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号