package com.jspsmart.upload;import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;// Referenced classes of package com.jspsmart.upload:
//            SmartUploadException, SmartUploadpublic class File
{    File()
    {
        m_startData = 0;
        m_endData = 0;
        m_size = 0;
        m_fieldname = new String();
        m_filename = new String();
        m_fileExt = new String();
        m_filePathName = new String();
        m_contentType = new String();
        m_contentDisp = new String();
        m_typeMime = new String();
        m_subTypeMime = new String();
        m_contentString = new String();
        m_isMissing = true;
    }    public void saveAs(String s)
        throws IOException, SmartUploadException
    {
        saveAs(s, 0);
    }    public void saveAs(String s, int i)
        throws IOException, SmartUploadException
    {
        String s1 = new String();
        s1 = m_parent.getPhysicalPath(s, i);
        if(s1 == null)
            throw new IllegalArgumentException("There is no specified destination file (1140).");
        try
        {
            java.io.File file = new java.io.File(s1);
            FileOutputStream fileoutputstream = new FileOutputStream(file);
            fileoutputstream.write(m_parent.m_binArray, m_startData, m_size);
            fileoutputstream.close();
        }
        catch(IOException ioexception)
        {
            throw new SmartUploadException("File can't be saved (1120).");
        }
    }    public void fileToField(ResultSet resultset, String s)
        throws ServletException, IOException, SmartUploadException, SQLException
    {
        long l = 0L;
        int i = 0x10000;
        int j = 0;
        int k = m_startData;
        if(resultset == null)
            throw new IllegalArgumentException("The RecordSet cannot be null (1145).");
        if(s == null)
            throw new IllegalArgumentException("The columnName cannot be null (1150).");
        if(s.length() == 0)
            throw new IllegalArgumentException("The columnName cannot be empty (1155).");
        l = BigInteger.valueOf(m_size).divide(BigInteger.valueOf(i)).longValue();
        j = BigInteger.valueOf(m_size).mod(BigInteger.valueOf(i)).intValue();
        try
        {
            for(int i1 = 1; (long)i1 < l; i1++)
            {
                resultset.updateBinaryStream(s, new ByteArrayInputStream(m_parent.m_binArray, k, i), i);
                k = k != 0 ? k : 1;
                k = i1 * i + m_startData;
            }            if(j > 0)
                resultset.updateBinaryStream(s, new ByteArrayInputStream(m_parent.m_binArray, k, j), j);
        }
        catch(SQLException sqlexception)
        {
            byte abyte0[] = new byte[m_size];
            System.arraycopy(m_parent.m_binArray, m_startData, abyte0, 0, m_size);
            resultset.updateBytes(s, abyte0);
        }
        catch(Exception exception)
        {
            throw new SmartUploadException("Unable to save file in the DataBase (1130).");
        }
    }    public boolean isMissing()
    {
        return m_isMissing;
    }    public String getFieldName()
    {
        return m_fieldname;
    }    public String getFileName()
    {
        return m_filename;
    }    public String getFilePathName()
    {
        return m_filePathName;
    }    public String getFileExt()
    {
        return m_fileExt;
    }    public String getContentType()
    {
        return m_contentType;
    }    public String getContentDisp()
    {
        return m_contentDisp;
    }    public String getContentString()
    {
        String s = new String(m_parent.m_binArray, m_startData, m_size);
        return s;
    }    public String getTypeMIME()
        throws IOException
    {
        return m_typeMime;
    }    public String getSubTypeMIME()
    {
        return m_subTypeMime;
    }    public int getSize()
    {
        return m_size;
    }    protected int getStartData()
    {
        return m_startData;
    }    protected int getEndData()
    {
        return m_endData;
    }    protected void setParent(SmartUpload smartupload)
    {
        m_parent = smartupload;
    }    protected void setStartData(int i)
    {
        m_startData = i;
    }    protected void setEndData(int i)
    {
        m_endData = i;
    }    protected void setSize(int i)
    {
        m_size = i;
    }    protected void setIsMissing(boolean flag)
    {
        m_isMissing = flag;
    }    protected void setFieldName(String s)
    {
        m_fieldname = s;
    }    protected void setFileName(String s)
    {
        m_filename = s;
    }    protected void setFilePathName(String s)
    {
        m_filePathName = s;
    }    protected void setFileExt(String s)
    {
        m_fileExt = s;
    }    protected void setContentType(String s)
    {
        m_contentType = s;
    }    protected void setContentDisp(String s)
    {
        m_contentDisp = s;
    }    protected void setTypeMIME(String s)
    {
        m_typeMime = s;
    }    protected void setSubTypeMIME(String s)
    {
        m_subTypeMime = s;
    }    public byte getBinaryData(int i)
    {
        if(m_startData + i > m_endData)
            throw new ArrayIndexOutOfBoundsException("Index Out of range (1115).");
        if(m_startData + i <= m_endData)
            return m_parent.m_binArray[m_startData + i];
        else
            return 0;
    }    private SmartUpload m_parent;
    private int m_startData;
    private int m_endData;
    private int m_size;
    private String m_fieldname;
    private String m_filename;
    private String m_fileExt;
    private String m_filePathName;
    private String m_contentType;
    private String m_contentDisp;
    private String m_typeMime;
    private String m_subTypeMime;
    private String m_contentString;
    private boolean m_isMissing;
    public static final int SAVEAS_AUTO = 0;
    public static final int SAVEAS_VIRTUAL = 1;
    public static final int SAVEAS_PHYSICAL = 2;
}

解决方案 »

  1.   

    package com.jspsmart.upload;
    public class SmartUploadException extends Exception
    {    SmartUploadException(String s)
        {
            super(s);
        }
    }
      

  2.   

    package com.jspsmart.upload;import java.io.IOException;
    import java.util.*;// Referenced classes of package com.jspsmart.upload:
    //            File, SmartUploadpublic class Files
    {    Files()
        {
            m_files = new Hashtable();
            m_counter = 0;
        }    protected void addFile(File file)
        {
            if(file == null)
            {
                throw new IllegalArgumentException("newFile cannot be null.");
            } else
            {
                m_files.put(new Integer(m_counter), file);
                m_counter++;
                return;
            }
        }    public File getFile(int i)
        {
            if(i < 0)
                throw new IllegalArgumentException("File's index cannot be a negative value (1210).");
            File file = (File)m_files.get(new Integer(i));
            if(file == null)
                throw new IllegalArgumentException("Files' name is invalid or does not exist (1205).");
            else
                return file;
        }    public int getCount()
        {
            return m_counter;
        }    public long getSize()
            throws IOException
        {
            long l = 0L;
            for(int i = 0; i < m_counter; i++)
                l += getFile(i).getSize();        return l;
        }    public Collection getCollection()
        {
            return m_files.values();
        }    public Enumeration getEnumeration()
        {
            return m_files.elements();
        }    private SmartUpload m_parent;
        private Hashtable m_files;
        private int m_counter;
    }
      

  3.   

    服务器如果是WEB,客户端就用HTTP协议upload , 如果是个SOCKET 服务器,就建个连接把文件传上去。无论是那种,都需要做客户端和服务端的程序。
      

  4.   

    是web端还是client端呀?
    传了半天才发现是client,郁闷
      

  5.   

    两位哥哥,是客户端,如何让客户端读取本地文件写入到服务器的数据库或目录中,如果用SmartUpload如何做?不过......
      

  6.   

    herosword(南),是客户端,你说使用http的upload,(我该如何做,能具体说说吗?
      

  7.   

    不难呀。
    你在服务器端做一个socket servet,在客户端做一个socket client,然后把文件变成文件流,采用datainputstream和dataoutputstream传输数据
      

  8.   

    我只能选择用Http协议来实现,可是具体怎么实现我不知道。高手门再哪里。得到答案后,以下两个贴子的分全部赠送:http://community.csdn.net/Expert/topic/3188/3188861.xml?temp=.162945
    http://community.csdn.net/Expert/topic/3188/3188392.xml?temp=.4402887
      

  9.   

    除了Socket外,还有更好的建议吗?
      

  10.   

    做一个ftp客户端,服务器装一个ftp服务器就行了
      

  11.   

    Socket FTP都不让用,只能通过http协议,能完成吗?
      

  12.   

    楼主,这个问题有什么特别的吗。传个文件是C/S程序常常要用到的功能。我以前好像有做过一个http方式的,email告诉我,我发给你。可以用若干种方案解决传文件的问题,
    从底层的socket到上层的 ftp/http/web/soap等等。
      

  13.   

    [email protected]先谢谢 usabcd(9号公路上的3名共军)
      

  14.   

    usabcd(9号公路上的3名共军)
    :
    有空请帮忙传个例子,谢谢。[email protected]