易截截图软件、单文件、免安装、纯绿色、仅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入门

 Java学习从入门到精通 
一、 JDK (Java Development Kit) 
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......

java自学点滴


String 与 StringBuffer区别:
String字符串对象是不可变的;StringBuffer是变长和可写的动态字符序列,可以自动地增加空间。
Integer var = new Integer();//有语法错误
Integer var = new Integer(2);//是对的
java的Vector成员是要用elementAt(i)成员函数来获得的,不能用ve[i]得到。
Vector::public Enumeration& ......

Java编程规范

 package的命名 package 的名字由全部小写的字母组成,例如:cn.mybole。
class和interface的命名 class和interface的名字由大写字母开头而其他字母都小写的单词组成,例如:Person,RuntimeException。
class变量的命名 变量的名字用一个小写字母开头,后面的单词用大写字母开头,例如:index,currentImage。
clas ......

java环境配置

cmd
set path=javac所在文件夹(不包括javac)
在任意文件夹下直接使用javac.exe,但当cmd 关闭时,就不再起作用
set classpath=...
作用:在任意文件夹下直接使用.class文件,但当cmd 关闭时,就不瑞起作用
查看:set pathh; set classpath
我的电脑->属性->高级->环境变量设置
用户变量:
变量名:classpat ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号