黑马程序员技术交流社区
标题:
求救,哪里需要改?
[打印本页]
作者:
ysdolls
时间:
2014-8-7 19:37
标题:
求救,哪里需要改?
package com.ys;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.SequenceInputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
public class heldFile {
//隐藏文件到图片
public static void inputMyFile(File file1,File file2,File file3) throws Exception{
ArrayList<FileInputStream> al = new ArrayList<FileInputStream>();
al.add(new FileInputStream(file1));
al.add(new FileInputStream(file2));
final Iterator<FileInputStream> it = al.iterator();
Enumeration<FileInputStream> en = new Enumeration<FileInputStream>()
{
public boolean hasMoreElements()
{
return it.hasNext();
}
public FileInputStream nextElement()
{
return it.next();
}
};
SequenceInputStream sis = new SequenceInputStream(en);
FileOutputStream fs = new FileOutputStream(file3);
BufferedOutputStream fos = new BufferedOutputStream(fs);
byte[] buf = new byte[1024];
int len = 0;
while((len=sis.read(buf))!=-1)
{
fos.write(buf,0,len);
}
fos.close();
sis.close();
}
public static void splitFile(File file1,File file2) throws Exception{
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
byte[] buf = new byte[290239];
int len = 0;
int count = 1;
while((len=fis.read(buf))!=-1)
{
if(count==1){
count++;
continue;
}else{
fos.write(buf,0,len);
fos.flush();
}
}
fos.close();
fis.close();
}
public static void main(String[] args) throws Exception {
File file1 = new File("/users/sakura/desktop/3.jpg");//路径为图片文件绝对路径
File file2 = new File("/users/sakura/desktop/1.mp3");//要隐藏的文件路径
File file3 = new File("/users/sakura/desktop/ImNewJpg.jpg");//隐藏时生成的新图片文件绝对路径
File file4 = new File("/users/sakura/desktop/1.txt");//分解时生成的被隐藏文件的绝对路径
//下面两个方法按不同需求选择调用。
inputMyFile(file1,file2,file3);//隐藏文件方法调用,若分解文件则注释掉
// splitFile(file3,file4);//分解文件方法,若隐藏文件则注释掉
}
}
复制代码
file2是小文件的话200k可以成功运行
不过我换了一个mp3文件就不行了 求解答
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2