IO-练习题-java

题目1

(1)将一个视频文件,切割成指定大小的文件块
(2)将上面切割出来的文件,合并成一个文件

mport java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class Test2 {

	public static void main(String[] args) throws Exception {
	    //	cut切视频
        //cut("d:/tomcat.wmv");
//		System.out.println("切割完成!");
		//和视频
		complex();
		System.out.println("合成完成");
		
	}
	static void cut(String video) throws Exception{
		InputStream in = new FileInputStream(video);
		byte [] buff = new byte[1024 * 1024];
		int count = 1;
		int len = 0;
		while((len = in.read(buff)) != -1) {
			OutputStream out = new FileOutputStream("d://碎片//part_"+count++);
			out.write(buff, 0, len);
			out.close();
		}
		in.close();
	}
	static void complex() throws  Exception{
		OutputStream out = new FileOutputStream("d://合好的视频.wmv");
		File f = new File("d://碎片");
		File [] fileList = f.listFiles();
		for(File file : fileList ) {
			InputStream in = new FileInputStream(file);
			byte [] buff = new byte[in.available()];
			in.read(buff);
			out.write(buff);
			in.close();
		}
		out.close();	
	}
	
}

题目2

请写一个函数, 该函数实现这样的功能:
1 将文件index.html 复制到 d盘
2 复制后的文件中,10.10.10.15:8080 这样的内容,可以在复制的过程中指定,用别的ip代换

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Scanner;

public class Test3 {

	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		System.out.println("请输入要替换的url");
		String url = scan.next();
		copy("10.10.10.15:8080",url) ;
		System.out.println("替换成功");
	}
	//將文件复制到d盘
	static void copy(String str,String url) throws IOException {
		Reader r = new FileReader("d://1.html");
		BufferedReader br = new BufferedReader(r);
		
		Writer w = new FileWriter("d://碎片//1_copy.html");	
		BufferedWriter  bw =new BufferedWriter(w);
		
		String mb ="";
		while((mb=br.readLine()) != null) {
			bw.write(mb.replace(str,url));
			bw.newLine();
			bw.flush();
		}
		br.close();
		bw.close();
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值