小弟刚学java,在编写server向client传送文件时,第一次传到client的指定位置成功,第二次就弹出无法访问存储路径的错误
以下是代码:服务器端:
package sterning;import java.net.*;
import java.io.*;public class SERVER extends Thread{
  private Socket client;  public SERVER(Socket c){
  this.client=c;
 }  public static void main(String[] args)throws IOException{
  ServerSocket server=new ServerSocket(5678);
  
  while(true){
  //transfer location change Single User or Multi User
  SERVER mu=new SERVER(server.accept());
  mu.start();
  }
  }
  
  public static byte[] i2b(int i) {  
      return new byte[]{  
              (byte) ((i >> 24) & 0xFF),  
              (byte) ((i >> 16) & 0xFF),  
              (byte) ((i >> 8) & 0xFF),  
              (byte) (i & 0xFF)  
      };  
  }  
  
 public void run(){ 
 try{ 
        BufferedReader in=new BufferedReader(new InputStreamReader(client.getInputStream()));
        PrintWriter out=new PrintWriter(client.getOutputStream());
        BufferedReader wt=new BufferedReader(new InputStreamReader(System.in));
        //Mutil User but can't parallel
     while(true){
      System.out.println("请输入文件夹路径:");
      String path = wt.readLine(); 
      out.flush();
      String filename=in.readLine();
      if(filename.equals("index")){
      }
      else if(filename.equals("end"))      
      break;
      else{
      out.println("ok");
      path += filename;
      System.out.println(path);
      File fi = new File(path);
      if(fi.exists()){
      System.out.println("文件长度:" + (int) fi.length());
      FileInputStream is = new FileInputStream(path);  
          OutputStream os = client.getOutputStream();  
          
          try {
           int length = (int) fi.length();  
              System.out.println("发送文件:" + fi.getName() + ",长度:" + length);  
              // 发送文件名和文件内容  
              writeFileName(fi, os);  
              writeFileContent(is, os, length);  
          } 
          finally{
           os.close();  
              is.close();  
          }  
      }
      else{
      System.out.println("error");
      }
      }
     }
     client.close(); 
 }
 catch(IOException ex){
 }
 finally{
 }
}
 
 private void writeFileContent(InputStream is, OutputStream os, int length) throws IOException {
 // 输出文件长度  
     os.write(i2b(length));       // 输出文件内容  
     byte[] buffer = new byte[4096];  
     int size;  
     while ((size = is.read(buffer)) != -1) {  
         os.write(buffer, 0, size);  
     }  
 }   // 输出文件名  
 private void writeFileName(File file, OutputStream os) throws IOException {  
     byte[] fn_bytes = file.getName().getBytes();       os.write(i2b(fn_bytes.length));         // 输出文件名长度  
     os.write(fn_bytes);    // 输出文件名  
 }  }客户端:
package sterning;import java.net.*;
import java.io.*;public class CLIENT{
static Socket server; public static int b2i(byte[] b) {
int value = 0;  
    for (int i = 0; i < 4; i++) {
     int shift = (4 - 1 - i) * 8;  
        value += (b[i] & 0x000000FF) << shift;  
    }  
    return value;  
}
 
public static void main(String[] args)throws Exception{
server=new Socket(InetAddress.getLocalHost(),5678);
BufferedReader in=new BufferedReader(new InputStreamReader(server.getInputStream()));
PrintWriter out=new PrintWriter(server.getOutputStream());
BufferedReader wt=new BufferedReader(new InputStreamReader(System.in));
        
String savePath;
        int bufferSize = 8192;
        byte[] buf = new byte[bufferSize];
        int passedlen = 0;
        long len=0;
        
while(true){
savePath = "D:\\save\\";
String filename=wt.readLine();
out.println(filename);
out.flush();
if(filename.equals("end")){
System.out.println("客户端关闭");
break;
}
try {  
                InputStream is = server.getInputStream();  
                readAndSave(is,savePath);  
            } 
catch (IOException e) {  
                e.printStackTrace();  
            } 
/*finally {
try {  
                    server.close();  
                } 
                catch (IOException e) {  
                    // nothing to do  
                }  
            }  */

out.flush();
}
server.close();
}

private static void readAndSave(InputStream is, String savePath) throws IOException {  
        String filename = getFileName(is);  
        int file_len = readInteger(is);  
        System.out.println("接收文件:" + filename + ",长度:" + file_len);          readAndSave0(is, savePath + filename, file_len);          System.out.println("文件保存成功(" + file_len + "字节)。");  
    }      private static void readAndSave0(InputStream is, String path, int file_len) throws IOException {  
        FileOutputStream os = getFileOS(path);  
        readAndWrite(is, os, file_len);  
        os.close();  
    }      // 边读边写,直到读取 size 个字节  
    private static void readAndWrite(InputStream is, FileOutputStream os, int size) throws IOException {  
        byte[] buffer = new byte[4096];  
        int count = 0;  
        while (count < size) {  
            int n = is.read(buffer);  
            // 这里没有考虑 n = -1 的情况  
            os.write(buffer, 0, n);  
            count += n;  
        }  
    }      // 读取文件名  
    private static String getFileName(InputStream is) throws IOException {  
        int name_len = readInteger(is);  
        byte[] result = new byte[name_len];  
        is.read(result);  
        return new String(result);  
    }      // 读取一个数字  
    private static int readInteger(InputStream is) throws IOException {  
        byte[] bytes = new byte[4];  
        is.read(bytes);  
        return b2i(bytes);  
    }      // 创建文件并返回输出流  
    private static FileOutputStream getFileOS(String path) throws IOException {  
        File file = new File(path);  
        if (!file.exists()) {  
            file.createNewFile();  
        }          return new FileOutputStream(file);  
    }  
}执行结果:
服务器端结果                                                             客户端结果
请输入文件夹路径:                                                    12345.txt
D:\                                                                              接收文件:12345.txt,长度:5
D:\12345.txt                                                             文件保存成功(5字节)。
文件长度:5                                                                  12345.txt
发送文件:12345.txt,长度:5                                                                                         
请输入文件夹路径:                                                      接收文件:,长度:0
D:\                                                                                 java.io.FileNotFoundException: D:\save (拒绝访问。)
                                                                                      at java.io.FileOutputStream.open(Native Method)
                                                                              at java.io.FileOutputStream.<init>(Unknown Source)
                                                                              at java.io.FileOutputStream.<init>(Unknown Source)
                                                                              at sterning.CLIENT.getFileOS(CLIENT.java:110)
                                                                              at sterning.CLIENT.readAndSave0(CLIENT.java:71)
                                                                              at sterning.CLIENT.readAndSave(CLIENT.java:65)
                                                                              at sterning.CLIENT.main(CLIENT.java:41)
不知道是什么错误,望高手多多帮忙。