给你一个,是我结合一些相关书籍写的,请指教
/**
* 文件拷贝。
*
*@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();
}
}
}
BufferedOutputStream,和BufferedInputStream这个输出输入流建立一个缓冲区
其实没必要用到可读写的RandomAccessFile来写
多谢提醒!