题目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();
}
}