/**
* 文件拷贝。
*
*@param from 源路径。
*@param to 目标路径。
*@exception IOException Description of the Exception
*/
public static void copy( String from, String to )
throws IOException
{
int BUFF_SIZE = 100000;
byte[] buffer = new byte[ BUFF_SIZE ];
InputStream in = null;
OutputStream out = null; try
{
in = new FileInputStream( from );
out = new FileOutputStream( to ); while ( true )
{
synchronized ( buffer )
{
int amountRead = in.read( buffer ); if ( amountRead == -1 )
{
break;
} out.write( buffer, 0, amountRead );
}
}
}
finally
{
if ( in != null )
{
in.close();
} if ( out != null )
{
out.close();
}
}
}
* 文件拷贝。
*
*@param from 源路径。
*@param to 目标路径。
*@exception IOException Description of the Exception
*/
public static void copy( String from, String to )
throws IOException
{
int BUFF_SIZE = 100000;
byte[] buffer = new byte[ BUFF_SIZE ];
InputStream in = null;
OutputStream out = null; try
{
in = new FileInputStream( from );
out = new FileOutputStream( to ); while ( true )
{
synchronized ( buffer )
{
int amountRead = in.read( buffer ); if ( amountRead == -1 )
{
break;
} out.write( buffer, 0, amountRead );
}
}
}
finally
{
if ( in != null )
{
in.close();
} if ( out != null )
{
out.close();
}
}
}
开两个文件流,一进一出,
FileInputStream in
FileOutputStream out
然后按byte读取->写入(要加try-catch呦)
byte buf[] = new byte[1024];
while((length = in.read(buf,0,1024))!=-1){
out.write(buf,0,length);
}关闭流们