/**
* 文件拷贝。
*
*@param from 源路径。
*@param to 目标路径。
*@exception IOException Description of the Exception
*/
public static void move( 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 );
}
}
in.close();
out.close(); File f=new File(from);
if(!f.exists()) {
System.out.println("file not found");
return;
}
f.delete(); }
finally
{
if ( in != null )
{
in.close();
} if ( out != null )
{
out.close();
}
}
}
* 文件拷贝。
*
*@param from 源路径。
*@param to 目标路径。
*@exception IOException Description of the Exception
*/
public static void move( 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 );
}
}
in.close();
out.close(); File f=new File(from);
if(!f.exists()) {
System.out.println("file not found");
return;
}
f.delete(); }
finally
{
if ( in != null )
{
in.close();
} if ( out != null )
{
out.close();
}
}
}
解决方案 »
- 怎么用JList实现类似QQ好友列表中的好友分组及该组下的好友显示。(注意:组名的高度比用户的高度小)
- 请教一个问题,JAVA调用DLL时参数传递的问题
- java 文本框内容改变事件
- swing与SWT问题,欢迎高手来解决!
- 大家帮忙看一下关于JAVA是参数传递是传值还是传引用的问题???
- !!!求助连接sqlserver2000的问题,大家帮忙啊
- 150分:求一个例子,当你碰到一个技术难题时,你一般怎么样去解决它?
- 高分求解,在JMX的Relation service中,一个Mbean只能充当一个role吗?
- 在线等待,一个关于java连接数据库的问题。
- 调查一下,大家过节费有多少,:)
- 学java,考证意义大吗?
- Multiple process in java
public static void CopyFiles(String fSName,String fDName)
{
File inFile = new File(fSName);
File outFile = new File(fDName);
if (inFile.isDirectory())
{
outFile.mkdir();
File[] listFiles = inFile.listFiles();
for(int i = 0;i < listFiles.length;i ++)
{
String fileName1 = listFiles[i].getPath();
String fileName2 = outFile.getPath() + System.getProperty("file.separator") + listFiles[i].getName();
System.out.println(fileName1 + " " + fileName2);
CopyFiles(fileName1,fileName2);
}
}
if (inFile.isFile())
{
try
{
DataInputStream in = new DataInputStream(
new BufferedInputStream(
new FileInputStream(inFile)));
DataOutputStream out;
if (outFile.exists())
out = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(fDName)));
else
out = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(outFile)));
byte [] buf = new byte[1024];
int nums,offset=0;
while ((nums = in.read(buf,offset,1024)) != -1)
{
out.write(buf,offset,nums);
}
System.out.println("nums:" + nums);
out.close();
in.close();
}
catch (FileNotFoundException e)
{
System.out.println("File Not Find!");
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
}