format報錯
package com.chatroom;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerChat {
?? ?public? static void main(String[] args){
?? ??? ?new ServerChat().startUp();
?? ?}
?? ?public void startUp(){
?? ??? ?ServerSocket ss= null;
?? ??? ?Socket s= null;
?? ??? ?String name = "[%s:%s"];
?? ??? ?//后面放端口
?? ??? ?try {
?? ??? ??? ?ss=new ServerSocket(12345);
?? ??? ??? ?System.out.println("服務器已啟動...");
?? ??? ??? ?s = ss.accept();
?? ??? ??? ?System.out.println(String.format(name,s.getInetAddress().getHostAddress(),s.getPort()));
?? ??? ?} catch (IOException e) {
?? ??? ??? ?
?? ??? ??? ?e.printStackTrace();
?? ??? ?}?? ?finally{
?? ??? ??? ?try {
?? ??? ??? ??? ?if (s!=null)? ss.close();
?? ??? ??? ??? ?if (ss!=null)? s.close();
?? ??? ??? ?} catch (IOException e) {
?? ??? ??? ??? ?e.printStackTrace();
?? ??? ??? ?}
?? ??? ?}
?? ?}
2015-04-24
?String name = "[%s:%s"];這個寫的不對吧