「java测试完整版」java开发测试
本篇文章给大家谈谈java测试完整版,以及java开发测试对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
java如何测试连接ftp是否通
java测试连接ftp是否连通可以使用判断是否有异常来决定,实例如下:
/**
* connectServer
* 连接ftp服务器
* @throws java.io.IOException
* @param path 文件夹,空代表根目录
* @param password 密码
* @param user 登陆用户
* @param server 服务器地址
*/
public void connectServer(String server, String user, String password, String path)
throws IOException
{
// server:FTP服务器的IP地址;user:登录FTP服务器的用户名
// password:登录FTP服务器的用户名的口令;path:FTP服务器上的路径
ftpClient = new FtpClient();
ftpClient.openServer(server);
ftpClient.login(user, password);
//path是ftp服务下主目录的子目录
if (path.length() != 0) ftpClient.cd(path);
//用2进制上传、下载
ftpClient.binary();
}
/**
* upload
* 上传文件
* @throws java.lang.Exception
* @return -1 文件不存在
* -2 文件内容为空
* 0 成功上传,返回文件的大小
* @param newname 上传后的新文件名
* @param filename 上传的文件
*/
public long upload(String filename,String newname) throws Exception
{
long result = 0;
TelnetOutputStream os = null;
FileInputStream is = null;
try {
java.io.File file_in = new java.io.File(filename);
if (!file_in.exists()) return -1;
if (file_in.length()==0) return -2;
os = ftpClient.put(newname);
result = file_in.length();
is = new FileInputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ((c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
}
} finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
}
return result;
}
/**
* upload
* @throws java.lang.Exception
* @return
* @param filename
*/
public long upload(String filename)
throws Exception
{
String newname = "";
if (filename.indexOf("/")-1)
{
newname = filename.substring(filename.lastIndexOf("/")+1);
}else
{
newname = filename;
}
return upload(filename,newname);
}
/**
* download
* 从ftp下载文件到本地
* @throws java.lang.Exception
* @return
* @param newfilename 本地生成的文件名
* @param filename 服务器上的文件名
*/
public long download(String filename,String newfilename)
throws Exception
{
long result = 0;
TelnetInputStream is = null;
FileOutputStream os = null;
try
{
is = ftpClient.get(filename);
java.io.File outfile = new java.io.File(newfilename);
os = new FileOutputStream(outfile);
byte[] bytes = new byte[1024];
int c;
while ((c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
result = result + c;
}
} catch (IOException e)
{
e.printStackTrace();
}
finally {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
}
return result;
}
/**
* 取得某个目录下的所有文件列表
*
*/
public List getFileList(String path)
{
List list = new ArrayList();
try
{
DataInputStream dis = new DataInputStream(ftpClient.nameList(path));
String filename = "";
while((filename=dis.readLine())!=null)
{
list.add(filename);
}
} catch (Exception e)
{
e.printStackTrace();
}
return list;
}
/**
* closeServer
* 断开与ftp服务器的链接
* @throws java.io.IOException
*/
public void closeServer()
throws IOException
{
try
{
if (ftpClient != null)
{
ftpClient.closeServer();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String [] args) throws Exception
{
FtpUtil ftp = new FtpUtil();
try {
//连接ftp服务器
("10.163.7.15", "cxl", "1", "info2");
/** 上传文件到 info2 文件夹下 */
System.out.println("filesize:"+("f:/download/Install.exe")+"字节");
/** 取得info2文件夹下的所有文件列表,并下载到 E盘下 */
List list = (".");
for (int i=0;ilist.size();i++)
{
String filename = (String)list.get(i);
System.out.println(filename);
(filename,"E:/"+filename);
}
} catch (Exception e) {
///
}finally
{
;
}
}
}
java单元测试怎么用
单元测试使用方式如下:
用单元测试可以找到程序入口,不再需要main方法。必须在需要执行的方法上面加@Test
注解释,导如org.junit.Test包。下面一个小例子供参考:
/**
* 单元测试
*
* @author qd
*
*/
public class Unit {
@Test
public void testUnit() {
System.out.println("单元测试运行成功");
}
}
注意:
1、方法返回值类型必须是void
2、不能是static的
JAVA基础测试题
1 跟java运行的机制有关,java先加载静态域,static int x=10; ,然后静态块static { x+=5;},static { x/=3;}(虽然位置在后但先运行) ,然后静态方法static void main
所以x=10,x=15,x=5.
2 A因为int [ ] x = new int[25],数组建立后,每个元素默认值为0;x[24]=0;x[25] 下标越界,x[0]=0;
3 switch(i)不接受long型,int或者枚举型可以。i=Integer.parseInt(args[0]);虽然这样每课时i还是long型的。
4 c,没什么好说的,就是这么规定的!
java基础测试题
答案为 C。
public Test(){
x=35;
}
public Test(String s){}
为构造方法,构造方法规定是不需要用void之类的修饰,也没有返回值
public void Test(double f){
this.x=(int)f;
},这个则是与类名同名的方法,但这样的做法不赞同。
java 测试题,紧急!
public class student
{
int snum;//xuehao
String name;
int escore;//englishscore;
int mscore;
int cscore;//computerscore;
public void setsnum(int snum){this.snum=snum;}
public void setname(String name){this.name=name;}
public void setescore(int escore){this.escore=escore;}
public void setmscore(int mscore){this.escore=escore;}
public void setcscore(int cscore){this.escore=escore;}
public int getsnum(){return snum;}
public String getname(){return name;}
public int getscore(){return escore;}
public int getmcore(){return mscore;}
public int getccore(){return cscore;}
public student(int snum,String name,int escore,int mscore,int cscore)
{
this.setsnum(snum);
this.setname(name);
this.setescore(escore);
this.setmscore(escore);
this.setcscore(escore);
}
public String toString()
{return "snum="+snum+"\t name="+name+"\t escore"+escore+"\t mscore"+mcore+"\t cscore"+cscore;}
public int sum(student e)
{return e.getescore()+e.getmscore()+e.getcscore();}
public String compare(Student e1 ,student e2)
{if(e1.sum()==e2.sum())return "等于";
else retuen (e1.sum()e2.sum())?"大于":"小于";}
public float testscore(student e)
{return (e.getescore()+e.getmscore()+e.getcscore())/3;}
public static voia main(String args[])
{
student stu=new student(1,"1",2,3,4);
studentxw sxw=new studentxw(1,"1",2,3,4,"work");
studentxw sbz=new studentbz(1,"1",2,3,4,"work1");
}
}
class studentxw extends student
{
private String work;
public void setwork(String work){this.work=work;}
public String getwork(){return work;}
public studentxw(int snum,String name,int escore,int mscore,int cscore,String work)
{
super(snum,name,escore,mscore,cscore);
this.setwork(work);
}
public float testscore(student e)
{return super.test(e)+3;}
}
class studentbz extends student
{
private String work;
public void setwork(String work){this.work=work;}
public String getwork(){return work;}
public studentxw(int snum,String name,int escore,int mscore,int cscore,String work)
{
super(snum,name,escore,mscore,cscore);
this.setwork(work);
}
public float testscore(student e)
{return super.test(e)+5;}
}
java测试完整版的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java开发测试、java测试完整版的信息别忘了在本站进行查找喔。