做电影网站要几G空间的/黑龙江最新疫情通报
做电影网站要几G空间的,黑龙江最新疫情通报,大连建设网煤气查询,jsp做的当当网站的文档Java代码 import java.io.*; class DownThread extends Thread { //定义字节数组(取水的竹筒)的长度 private final int BUFF_LEN 32; //定义读取的起始点 private long start; //定义读取的结束点 private long end; …
- import java.io.*;
- class DownThread extends Thread {
-
- private final int BUFF_LEN = 32;
-
- private long start;
-
- private long end;
-
- private InputStream is;
-
- private RandomAccessFile raf;
-
-
- public DownThread(long start, long end, InputStream is, RandomAccessFile raf) {
-
- System.out.println(start + "---->" + end);
- this.start = start;
- this.end = end;
- this.is = is;
- this.raf = raf;
- }
-
- public void run() {
- try {
- is.skip(start);
- raf.seek(start);
-
- byte[] buff = new byte[BUFF_LEN];
-
- long contentLen = end - start;
-
- long times = contentLen / BUFF_LEN + 4;
-
- int hasRead = 0;
- for (int i = 0; i < times; i++) {
- hasRead = is.read(buff);
-
- if (hasRead < 0) {
- break;
- }
- raf.write(buff, 0, hasRead);
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
-
- finally {
- try {
- if (is != null) {
- is.close();
- }
- if (raf != null) {
- raf.close();
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- }
- }
-
- public class MutilDown {
- public static void main(String[] args) {
- final int DOWN_THREAD_NUM = 4;
- final String OUT_FILE_NAME = "d:/copy勇敢的心.rmvb";
- InputStream[] isArr = new InputStream[DOWN_THREAD_NUM];
- RandomAccessFile[] outArr = new RandomAccessFile[DOWN_THREAD_NUM];
- try {
-
- isArr[0] = new FileInputStream("d:/勇敢的心.rmvb");
- long fileLen = getFileLength(new File("d:/勇敢的心.rmvb"));
- System.out.println("文件的大小" + fileLen);
-
- outArr[0] = new RandomAccessFile(OUT_FILE_NAME, "rw");
-
- for (int i = 0; i < fileLen; i++) {
- outArr[0].write(0);
- }
-
- long numPerThred = fileLen / DOWN_THREAD_NUM;
-
- long left = fileLen % DOWN_THREAD_NUM;
- for (int i = 0; i < DOWN_THREAD_NUM; i++) {
-
-
- if (i != 0) {
-
- isArr[i] = new FileInputStream("d:/勇敢的心.rmvb");
-
- outArr[i] = new RandomAccessFile(OUT_FILE_NAME, "rw");
- }
- if (i == DOWN_THREAD_NUM - 1) {
-
- new DownThread(i * numPerThred, (i + 1) * numPerThred
- + left, isArr[i], outArr[i]).start();
- } else {
-
- new DownThread(i * numPerThred, (i + 1) * numPerThred,
- isArr[i], outArr[i]).start();
- }
- }
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
-
- public static long getFileLength(File file) {
- long length = 0;
-
- long size = file.length();
- length = size;
- return length;
- }
- }
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/451454.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!