/**
* 文件拷贝。
*
*@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();
}
}
}
解决方案 »
- 我对String的一些见解(看了JAVA面试题解惑系列(二)——到底创建了几个String对象?之后)
- 关于接口的实现和内部类的问题
- 不同编码对应什么 或者什么是不同编码的界限
- 如何得到32位的MD5结果,sun的api得到的是16位的
- 如何在j2se的C/S系统中解决报表的问题?谢谢了
- 在JAVA中怎么判断俩个时间的 大小..各位高手。。谢谢 了
- UDP传输问题,马上给分!!!!!!!!!!!!!!
- string ---> byte[][]
- 请详细解释javamail里的“收件人类型”的CC,TO,BCC的意义???
- 太奇怪了,难道weblogic不能生成可以滚动的sql对象吗??送60分!!
- 学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());
}
}
}