标题:麻烦帮看段代码
取消只看楼主
半月
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2010-1-12
结帖率:75%
已结贴  问题点数:20 回复次数:0 
麻烦帮看段代码
public static void sendFile2Server(File local_file, String targeFile,
            String server, int port, String id) {
        Socket socket = null;
        InputStream iis = null;
        OutputStream os = null;
        try {
            socket = new Socket(server, port);
            byte[] fileNameBuf = targeFile.getBytes("GBK");
            int fls = fileNameBuf.length;
            byte[] fileNamelen = new byte[] { 0, 0, 0, 0 };
            fileNamelen[0] = (byte) ((fls >> 24) & 0xff);
            fileNamelen[1] = (byte) ((fls >> 16) & 0xff);
            fileNamelen[2] = (byte) ((fls >> 8) & 0xff);
            fileNamelen[3] = (byte) ((fls >> 0) & 0xff);

            os = socket.getOutputStream();
            os.write(SEND_HEADER);
            os.write(fileNamelen);
            os.write(fileNameBuf);
            os.flush();
            iis = new FileInputStream(local_file);
            byte[] buf = new byte[1024];
            int rl = iis.read(buf);
            while (rl > 0) {
                os.write(buf, 0, rl);
                rl = iis.read(buf);
            }
            FileTransferStauts.statusMap.put(id, "finished");
        } catch (Exception e) {
            FileTransferStauts.statusMap.put(id, e.getMessage());
        } finally {
            try {
                if (os != null)
                    os.close();
                if (socket != null && !socket.isClosed())
                    socket.close();
                if (iis != null)
                    iis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

红色的部分,对filename的操作有什么作用?
搜索更多相关主题的帖子: 麻烦 代码 
2010-01-12 12:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-295540-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.091864 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved