tangshuo 发表于 2013-1-27 05:27:08

通过WebService上传文件

        用WebService传输文件,实际上就是客户端将文件先做成比特流,然后调用webservice接口,服务端再将比特流还原成文件。下面是代码:
服务端:
<div style="padding: 4px 5.4pt; width: 95%;">http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gifpublic class FileTransferWs ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif    public int uploadFile(byte []bs, String fileName) ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        FileOutputStream out = null;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        try ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            String newFile = "C:\tmp\" + fileName;    //上传文件存放路径
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            out = new FileOutputStream(newFile);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif            try ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                out.write(bs);
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif            } catch (IOException e) ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                // TODO Auto-generated catch block
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                e.printStackTrace();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        } catch (FileNotFoundException e) ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            // TODO Auto-generated catch block
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            e.printStackTrace();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif            return -1;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif        } finally  ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif            if (out != null) ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif                try ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                    out.close();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gifhttp://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif                } catch (IOException e) ...{
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                    // TODO Auto-generated catch block
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif                    e.printStackTrace();
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif                }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif            }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif        }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif        return 0;
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif    }
http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif}
页: [1]
查看完整版本: 通过WebService上传文件