public class ServerTimedOutException extends Exception {
private int port;
public ServerTimedOutException(String message, int port) {
super(message);
this.port = port;
}
public int getPort( ) {
return port;
}
}
class Client {
// 在下行空白处填上声明抛出ServerTimedOutException异常的语句
public void connectMe(String serverName) {
int success;
int portToConnect = 80;
success = open(serverName, portToConnect)
if (success == -1) {
// 在下行空白处填上抛出ServerTimedOutException异常的语句
}
}
}
-------------------------
下列程序中,要求输出一个特定文件(这里是ex.java)的相关信息,包括文件的名字,相对路径以及文件的长度。请将程序补充完整(10分)。
import java.io.*;
public class ex {
public static void main(String[ ] args) {
File file1=new File("ex.java");
System.out.println("name:"+file1. getName() );
System.out.println("path:"+file1. );
System.out.println("length:"+file1. );
}
}
private int port;
public ServerTimedOutException(String message, int port) {
super(message);
this.port = port;
}
public int getPort( ) {
return port;
}
}
class Client {
// 在下行空白处填上声明抛出ServerTimedOutException异常的语句
public void connectMe(String serverName) {
int success;
int portToConnect = 80;
success = open(serverName, portToConnect)
if (success == -1) {
// 在下行空白处填上抛出ServerTimedOutException异常的语句
}
}
}
-------------------------
下列程序中,要求输出一个特定文件(这里是ex.java)的相关信息,包括文件的名字,相对路径以及文件的长度。请将程序补充完整(10分)。
import java.io.*;
public class ex {
public static void main(String[ ] args) {
File file1=new File("ex.java");
System.out.println("name:"+file1. getName() );
System.out.println("path:"+file1. );
System.out.println("length:"+file1. );
}
}
{
……
throw new ServerTimedOutException("自定义异常信息", portToConnect);
……
}◆
文件名称:getName();
相对路径:getPath();
文件长度:length();
2。getSize()