在java中下载的代码 网上下载的java代码怎么运行
求一个Java实现自动下载的源代码
您好,这样的:
目前创新互联建站已为超过千家的企业提供了网站建设、域名、雅安服务器托管、绵阳服务器托管、企业网站设计、新华网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
/**
*
*/
package com.b510.base.bean.install;
import java.io.File;
import java.io.FileWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author hongten(hongtenzone@foxmail.com)
* @date 2013-2-24
*/
@SuppressWarnings("unchecked")
public class BeanUtils {
//公共部分
private static final String RT_1 = "\r\n";
private static final String RT_2 = RT_1+RT_1;
private static final String BLANK_1 =" ";
private static final String BLANK_4 =" ";
private static final String BLANK_8 =BLANK_4 + BLANK_4;
//注释部分
private static final String ANNOTATION_AUTHOR_PARAMTER = "@author ";
private static final String ANNOTATION_AUTHOR_NAME = "hongten(hongtenzone@foxmail.com)";
private static final String ANNOTATION_AUTHOR = ANNOTATION_AUTHOR_PARAMTER + ANNOTATION_AUTHOR_NAME;
private static final String ANNOTATION_DATE = "@date ";
private static final String ANNOTATION = "/**"+RT_1+BLANK_1+"*"+BLANK_1+ANNOTATION_AUTHOR +RT_1+BLANK_1+"*"+BLANK_1+ANNOTATION_DATE +getDate()+RT_1+BLANK_1+"*/"+RT_1;
//文件 地址
//private static final String BEAN_PATH = "com/b510/base/bean";
private static final String DAO_PATH = "com/b510/base/dao";
private static final String DAO_IMPL_PATH = "com/b510/base/dao/impl";
private static final String SERVICE_PATH = "com/b510/base/service";
private static final String SERVICE_IMPL_PATH = "com/b510/base/service/impl";
//包名
private static final String BEAN_URL = "com.b510.base.bean";
private static final String DAO_URL = "com.b510.base.dao";
private static final String DAO_IMPL_URL = "com.b510.base.dao.impl";
private static final String SERVICE_URL = "com.b510.base.service";
private static final String SERVICE_IMPL_URL = "com.b510.base.service.impl";
//基本类名称
private static final String BASE_DAO_NAME = DAO_URL + ".BaseDao";
private static final String ABSTRACT_BASE_DAO_IMPL_NAME = DAO_IMPL_URL + ".AbstractBaseDaoImpl";
private static final String BASE_SERVICE_NAME = SERVICE_URL + ".BaseService";
private static final String ABSTRACT_BASE_SERVICE_IMPL_NAME = SERVICE_IMPL_URL + ".AbstractBaseServiceImpl";
/**
* 创建bean的Daobr
*
* @param c
* @throws Exception
*/
public void createBeanDao(Class c) throws Exception {
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + DAO_PATH
+ "/" + getLastChar(cName) + "Dao.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+DAO_URL+";"+RT_2+ANNOTATION+"public interface " +
getLastChar(cName) + "Dao extends "+BASE_DAO_NAME+" " + cName + " {"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的Dao的实现类
* @param c
* @throws Exception
*/
public void createBeanDaoImpl(Class c) throws Exception{
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + DAO_IMPL_PATH
+ "/" + getLastChar(cName) + "DaoImpl.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+DAO_IMPL_URL+";"+RT_2+ANNOTATION+"public class " +
getLastChar(cName) + "DaoImpl extends "+ABSTRACT_BASE_DAO_IMPL_NAME+"" +
cName + " implements "+DAO_URL+"."+getLastChar(cName)+"Dao{"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的service
* @param c
* @throws Exception
*/
public void createBeanService(Class c) throws Exception{
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + SERVICE_PATH
+ "/" + getLastChar(cName) + "Service.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+SERVICE_URL+";"+RT_2+ANNOTATION+"public interface " +
getLastChar(cName) + "Service extends "+BASE_SERVICE_NAME+""+ cName +"{"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 创建bean的service的实现类
* @param c
* @throws Exception
*/
public void createBeanServiceImpl(Class c) throws Exception{
String cName = c.getName();
String fileName = System.getProperty("user.dir") + "/src/" + SERVICE_IMPL_PATH
+ "/" +getLastChar(cName)+"ServiceImpl.java";
File f = new File(fileName);
FileWriter fw = new FileWriter(f);
fw.write("package "+SERVICE_IMPL_URL+";"+RT_2+ANNOTATION+"public class "
+ getLastChar(cName) + "ServiceImpl extends "+ABSTRACT_BASE_SERVICE_IMPL_NAME+""+ cName
+ " implements "+SERVICE_URL+"."+getLastChar(cName)+"Service{"+RT_2+BLANK_4
+"private "+DAO_URL+"."+getLastChar(cName)+"Dao "+getLowercaseChar(getLastChar(cName))
+"Dao;"+RT_2+BLANK_4+"public void set"+getLastChar(cName)+"Dao("+DAO_URL+"."+getLastChar(cName)+"Dao "
+getLowercaseChar(getLastChar(cName))+"Dao){"+RT_1+BLANK_8+"this."+getLowercaseChar(getLastChar(cName))+"Dao = "
+getLowercaseChar(getLastChar(cName))+"Dao;"+RT_1+BLANK_4+"}"+RT_2+BLANK_4+"@Override"+RT_1+BLANK_4
+"public "+DAO_URL+"."+"BaseDao"+BEAN_URL+"."+getLastChar(cName)+" getBaseDao(){"+RT_1+BLANK_8
+"return "+getLowercaseChar(getLastChar(cName))+"Dao;"+RT_1+BLANK_4+"}"+RT_2+"}");
fw.flush();
fw.close();
showInfo(fileName);
}
/**
* 获取路径的最后面字符串br
* 如:br
* codestr = "com.b510.base.bean.User"/codebr
* code return "User";code
* @param str
* @return
*/
public String getLastChar(String str) {
if ((str != null) (str.length() 0)) {
int dot = str.lastIndexOf('.');
if ((dot -1) (dot (str.length() - 1))) {
return str.substring(dot + 1);
}
}
return str;
}
/**
* 把第一个字母变为小写br
* 如:br
* codestr = "UserDao";/codebr
* codereturn "userDao";/code
* @param str
* @return
*/
public String getLowercaseChar(String str){
return str.substring(0,1).toLowerCase()+str.substring(1);
}
/**
* 显示信息
* @param info
*/
public void showInfo(String info){
System.out.println("创建文件:"+ info+ "成功!");
}
/**
* 获取系统时间
* @return
*/
public static String getDate(){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
return simpleDateFormat.format(new Date());
}
}
如何将下载的java源代码导入到eclipse中运行
eclipse打开并运行一个已经写好的java文件步骤如下:
1、新建一个java工程项目:右键Eclipse的PackageExplorer空白部分,点击New,再点击JavaProject,输入工程名,点击finish;
2、在新建的工程里新建一个类:右键工程,点击New,再点击Class,输入类名,点击finish;
3、把写好的java文件的代码复制到新建的类中;
4、右键新建的类文件,点击RunAs,再点击JavaApplication即可运行Java文件。
需要注意的是:java文件要成功运行,前提是要有主方法(main)的存在,没有主方法没办法运行java程序。
网上下载的java代码怎么在eclipse里运行阿?
网上下载的java代码在eclipse里运行方法:
1.打开eclipse,点击项目的空白处,选择import;
2.选择Existing Project into Workspace,点击next,找到下载的java代码,导入到eclipse中;
3.导入成功之后,选择项目,鼠标右键,选择run as,选择一个运行方式,然后运行即可。
Java中文件下载该怎么写代码求高手指导
if (upfile.exists()) {
bytes = FileUtils.readFileToByteArray(upfile);
response.setContentType("application/x-download");
String agent = request.getHeader("USER-AGENT");//用户代理
// 防止中文文件名乱码
if (null != agent -1 != agent.indexOf("MSIE")) {
String codedfilename = StringUtils.replace(URLEncoder.encode(fileName, "UTF-8"), "+", "%20");
response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename);
} else if (null != agent -1 != agent.indexOf("Mozilla")) {
String codedfilename = MimeUtility.encodeText(fileName, "UTF-8", "B");
response.setHeader("Content-Disposition", "attachment;filename=" + codedfilename);
} else {
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
}
response.setContentLength(bytes.length);
response.getOutputStream().write(bytes);
}
java下载方面的代码
你的这段代码有两处让人疑惑。其一、File()这个构造函数,自已查下API
其二、FileOutputStream,FileOutputStream(String name)创建一个向具有指定名称的文件中写入数据的输出文件流。它只是创建了一个输出流,其中没有具体的值,那么这个值来自哪呢,其就来自于你的输入流。其中FileOutputStream()中只是创建了一个字节输出流,其只能接受字节流的输出,所以它还需要与DataOutputStream()的配合才能完成输出,具体用法你可以查API
我在网上下载了一些java游戏程序代码,请问如何在电脑上运行
把所有的文件编译成类文件.class
(用javac
文件名.java
编译)
,
然后找到游戏代码的入口文件,java
文件名
运行,就完事了当然你得确保这是一个能在命令行下运行的代码
本文名称:在java中下载的代码 网上下载的java代码怎么运行
文章网址:http://pwwzsj.com/article/doospic.html