直接使用http连接的类连接到文件地址,再通过管道转到文件输出流不就完了?有什么难的,或者是我没看懂你的问题?

解决方案 »

  1.   

    jspSmartUpload的源代码,只要能写在硬盘上,都可以上传下载(这一部分是上传的)
    // Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
    // Decompiler options: packimports(3) fieldsfirst ansi 
    // Source File Name:   File.javapackage 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
    {    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;    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 destFilePathName)
            throws SmartUploadException, IOException
        {
            saveAs(destFilePathName, 0);
        }    public void saveAs(String destFilePathName, int optionSaveAs)
            throws SmartUploadException, IOException
        {
            String path = new String();
            path = m_parent.getPhysicalPath(destFilePathName, optionSaveAs);
            if(path == null)
                throw new IllegalArgumentException("There is no specified destination file (1140).");
            try
            {
                java.io.File file = new java.io.File(path);
                FileOutputStream fileOut = new FileOutputStream(file);
                fileOut.write(m_parent.m_binArray, m_startData, m_size);
                fileOut.close();
            }
            catch(IOException e)
            {
                throw new SmartUploadException("File can't be saved (1120).");
            }
        }    public void fileToField(ResultSet rs, String columnName)
            throws SQLException, SmartUploadException, IOException, ServletException
        {
            long numBlocks = 0L;
            int blockSize = 0x10000;
            int leftOver = 0;
            int pos = 0;
            if(rs == null)
                throw new IllegalArgumentException("The RecordSet cannot be null (1145).");
            if(columnName == null)
                throw new IllegalArgumentException("The columnName cannot be null (1150).");
            if(columnName.length() == 0)
                throw new IllegalArgumentException("The columnName cannot be empty (1155).");
            numBlocks = BigInteger.valueOf(m_size).divide(BigInteger.valueOf(blockSize)).longValue();
            leftOver = BigInteger.valueOf(m_size).mod(BigInteger.valueOf(blockSize)).intValue();
            try
            {
                for(int i = 1; (long)i < numBlocks; i++)
                {
                    rs.updateBinaryStream(columnName, new ByteArrayInputStream(m_parent.m_binArray, pos, blockSize), blockSize);
                    pos = pos != 0 ? pos : 1;
                    pos = i * blockSize;
                }            if(leftOver > 0)
                    rs.updateBinaryStream(columnName, new ByteArrayInputStream(m_parent.m_binArray, pos, leftOver), leftOver);
            }
            catch(SQLException e)
            {
                byte binByte2[] = new byte[m_size];
                System.arraycopy(m_parent.m_binArray, m_startData, binByte2, 0, m_size);
                rs.updateBytes(columnName, binByte2);
            }
            catch(Exception e)
            {
                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 strTMP = new String(m_parent.m_binArray, m_startData, m_size);
            return strTMP;
        }    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 parent)
        {
            m_parent = parent;
        }    protected void setStartData(int startData)
        {
            m_startData = startData;
        }    protected void setEndData(int endData)
        {
            m_endData = endData;
        }    protected void setSize(int size)
        {
            m_size = size;
        }    protected void setIsMissing(boolean isMissing)
        {
            m_isMissing = isMissing;
        }    protected void setFieldName(String fieldName)
        {
            m_fieldname = fieldName;
        }    protected void setFileName(String fileName)
        {
            m_filename = fileName;
        }    protected void setFilePathName(String filePathName)
        {
            m_filePathName = filePathName;
        }    protected void setFileExt(String fileExt)
        {
            m_fileExt = fileExt;
        }    protected void setContentType(String contentType)
        {
            m_contentType = contentType;
        }    protected void setContentDisp(String contentDisp)
        {
            m_contentDisp = contentDisp;
        }    protected void setTypeMIME(String TypeMime)
        {
            m_typeMime = TypeMime;
        }    protected void setSubTypeMIME(String subTypeMime)
        {
            m_subTypeMime = subTypeMime;
        }    public byte getBinaryData(int index)
        {
            if(m_startData + index > m_endData)
                throw new ArrayIndexOutOfBoundsException("Index Out of range (1115).");
            if(m_startData + index <= m_endData)
                return m_parent.m_binArray[m_startData + index];
            else
                return 0;
        }
    }
      

  2.   

    // Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
    // Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
    // Decompiler options: packimports(3) fieldsfirst ansi 
    // Source File Name:   Request.javapackage com.jspsmart.upload;import java.util.Enumeration;
    import java.util.Hashtable;public class Request
    {    private Hashtable m_parameters;
        private int m_counter;    Request()
        {
            m_parameters = new Hashtable();
            m_counter = 0;
        }    protected void putParameter(String name, String value)
        {
            if(name == null)
                throw new IllegalArgumentException("The name of an element cannot be null.");
            if(m_parameters.containsKey(name))
            {
                Hashtable values = (Hashtable)m_parameters.get(name);
                values.put(new Integer(values.size()), value);
            } else
            {
                Hashtable values = new Hashtable();
                values.put(new Integer(0), value);
                m_parameters.put(name, values);
                m_counter++;
            }
        }    public String getParameter(String name)
        {
            if(name == null)
                throw new IllegalArgumentException("Form's name is invalid or does not exist (1305).");
            Hashtable values = (Hashtable)m_parameters.get(name);
            if(values == null)
                return null;
            else
                return (String)values.get(new Integer(0));
        }    public Enumeration getParameterNames()
        {
            return m_parameters.keys();
        }    public String[] getParameterValues(String name)
        {
            if(name == null)
                throw new IllegalArgumentException("Form's name is invalid or does not exist (1305).");
            Hashtable values = (Hashtable)m_parameters.get(name);
            if(values == null)
                return null;
            String strValues[] = new String[values.size()];
            for(int i = 0; i < values.size(); i++)
                strValues[i] = (String)values.get(new Integer(i));        return strValues;
        }
    }
      

  3.   

    // Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
    // Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
    // Decompiler options: packimports(3) fieldsfirst ansi 
    // Source File Name:   Files.javapackage com.jspsmart.upload;import java.io.IOException;
    import java.util.*;// Referenced classes of package com.jspsmart.upload:
    //            File, SmartUploadpublic class Files
    {    private SmartUpload m_parent;
        private Hashtable m_files;
        private int m_counter;    Files()
        {
            m_files = new Hashtable();
            m_counter = 0;
        }    protected void addFile(File newFile)
        {
            if(newFile == null)
            {
                throw new IllegalArgumentException("newFile cannot be null.");
            } else
            {
                m_files.put(new Integer(m_counter), newFile);
                m_counter++;
                return;
            }
        }    public File getFile(int index)
        {
            if(index < 0)
                throw new IllegalArgumentException("File's index cannot be a negative value (1210).");
            File retval = (File)m_files.get(new Integer(index));
            if(retval == null)
                throw new IllegalArgumentException("Files' name is invalid or does not exist (1205).");
            else
                return retval;
        }    public int getCount()
        {
            return m_counter;
        }    public long getSize()
            throws IOException
        {
            long tmp = 0L;
            for(int i = 0; i < m_counter; i++)
                tmp += getFile(i).getSize();        return tmp;
        }    public Collection getCollection()
        {
            return m_files.values();
        }    public Enumeration getEnumeration()
        {
            return m_files.elements();
        }
    }