// 2 检查是否存在目标目录的
File f1 = new File(s2);
if ( ! f1.exists() )
{
f1.mkdir();
}
System.out.println( f1 );
// 3 用字节流遍历拷贝
BufferedOutputStream out = null;
BufferedInputStream in = null;
try
{
for (int i=0;i<fs.length ;i++ )
{
out = new BufferedOutputStream( new FileOutputStream(fs) );
in = new BufferedInputStream ( new FileInputStream(new File(f1,fs.getName())) );
byte [] by = new byte [1024];
int a = 0;
while ( (a=in.read(by))!=-1 )
{
out.write(by,0,a);
}
}
}
/*
//用字符流实现拷贝
BufferedReader in = null;
BufferedWriter out = null;
try
for ( int i = 0; i < fs.length ; i++ )
{
in = new BufferedReader( new FileReader( fs ) );
out = new BufferedWriter( new FileWriter( new File( f1, fs.getName() ) ) );
String str = null;
while ( (str = in.readLine()) != null )
{
out.write( str );
out.newLine();
}
}
}
*/
catch (Exception e)
{
System.out.println( e.toString() );
}
finally
{
try
{
if (in!=null)
{
in.close();
}
}
catch (Exception e)
{
in = null;
}
try
{
if (out!=null)
{
out.close();
}