要求从本地选择文件然后上传到服务器即可,用一个类实现.

解决方案 »

  1.   

    如果服务器有FTP服务,你就做一个FTP的客户端即可
    如果服务器有JSP服务,你可以用jspSmartUpload组件
    如果什么服务都没有,你需要用Socket通讯来自己实现,写一个服务器端程序来接收上传的文件和一个发送文件的客户端.
      

  2.   

    String exsistingFileName  = (String) file_path.getValue();
     
    try 
            { 
    String g = Global.getServerUrl();
    g = g.substring(g.indexOf("=") + 1, g.lastIndexOf("/") - 5);// 去掉 gfmis

                FileInputStream fileInputStream = new FileInputStream(new File(exsistingFileName));//exsistingFileName打包后的文件名 
                URL url = new URL(g);  //urlString是网页路径,这个路径负责解压后的文件处理。 
                HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 
                conn.setDoInput(true); 
                conn.setDoOutput(true); 
                conn.setUseCaches(false); 
                conn.setRequestMethod("POST"); 
                conn.setRequestProperty("Connection", "Keep-Alive"); 
                conn.setRequestProperty("Content-Type","multipart/form-data;boundary="); 
                DataOutputStream dos = new DataOutputStream(conn.getOutputStream()); 
    //            dos.writeBytes(twoHyphens + boundary + lineEnd); 
                dos.writeBytes("Content-Disposition: form-data; name=\"upload\";" + " filename=\"" + exsistingFileName + "\""); 
    //            dos.writeBytes(lineEnd);             // create a buffer of maximum size 
                int maxBufferSize = 1024;
                int bytesAvailable = fileInputStream.available(); 
                int bufferSize = Math.min(bytesAvailable, maxBufferSize); 
                byte[] buffer = new byte[bufferSize];             int bytesRead = fileInputStream.read(buffer, 0, bufferSize);             while (bytesRead > 0) 
                { 
                    dos.write(buffer, 0, bufferSize); 
                    bytesAvailable = fileInputStream.available(); 
                    bufferSize = Math.min(bytesAvailable, maxBufferSize); 
                    bytesRead = fileInputStream.read(buffer, 0, bufferSize); 
                } //            dos.writeBytes(lineEnd); 
    //            dos.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);             fileInputStream.close(); 
                dos.flush(); 
                dos.close();         } 
            catch (MalformedURLException ex) 
            { 
                
            } 
            catch (IOException ioe) 
            { 
                
            }

     
    刚抄袭的一个,不过应该还有一部分