今天突发奇想,想把手机中的微信中曾经的发过的图片和音频全部弄出来,最后发现靠点击文件夹然后copy这个方法太困难了,看过微信文件夹的童鞋们都知道,所有的图片和音频都存在不同的文件夹中,这就是我写这个程序的程序的初衷。
/*Author:bedlamite
* time:2014-7-4
*/
import java.io.*;
import java.nio.channels.FileChannel;
public class a
{
public static void main(String[] argv)throws Exception
{
File file = new File("D:\\result.txt");
PrintStream out = System.out;
PrintStream result = new PrintStream(file);
System.setOut(result);
File root = new File("C:\\Users\\TONY\\Desktop\\phone_voice3");
showAllFilr(root);
String file1_path = null;
String file2_path = null;
File file2 = null;
BufferedReader br = new BufferedReader(new FileReader("D:\\result.txt"));
String s = null;
int i = 0;
while((s=br.readLine())!=null)
{
String str = "D:\\log"+String.valueOf(i)+".amr";
file1_path = str;
if(s.indexOf(".amr")>=0)
{
System.setOut(out);
System.out.println(s);
file2_path = s;
File file1 = new File(file1_path);
file2 = new File(file2_path);
copyfile(file2,file1);
System.out.println(file1_path);
i++;
}
}
br.close();
}
final static void showAllFilr(File dir)throws Exception
{
File[] fs = dir.listFiles();
for(int i=0;i<fs.length;i++)
{
System.out.println(fs[i].getAbsolutePath());
if(fs[i].isDirectory())
{
try
{
showAllFilr(fs[i]);
}
catch(Exception e)
{
System.out.println("IOException e:"+e);
}
}
}
}
public static void copyfile(File sourse,File teminal)
{
/*
* 使用文件通道的方式来进行文件复制
* @param sourse
* 源文件
* @param teminal
*
*/
//(new File(newPath)).mkdir();
//File sourse = new File(oldPath);
//File teminal = new File(newPath);
FileInputStream fi = null;
FileOutputStream fo = null;
FileChannel in =null;
FileChannel out = null;
try
{
fi = new FileInputStream(sourse);
fo = new FileOutputStream(teminal);
in = fi.getChannel();
out = fo.getChannel();
in.transferTo(0, in.size(), out);
}
catch(IOException e)
{
e.printStackTrace();
System.out.println("the IOException is: "+e);
}finally
{
try
{
fi.close();
in.close();
fo.close();
out.close();
}catch(IOException e)
{
e.printStackTrace();
System.out.println("the IOException is: "+e);
}
}
}
}
这个可以把微信的文件夹的地址换成你的地址就可以,就可以得到图片和视频了,微信中的图片格式是.jpg格式,微信中的音频格式是.amr格式。