今天想通过数据库转移文件,想到java的流来进行处理。先读取文件生成流再把流专业后,再将流中的数据生成文件。
package word;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;


public class TestDoc
{

public static void main(String args[])
{
int bytesum=0;
int byteread=0;
InputStream inStream;

try
{
inStream = new FileInputStream("c:/1.xls");
FileOutputStream fs=new FileOutputStream("d:/aaa.xls");byte[] buffer =new byte[1444];
while ((byteread=inStream.read(buffer))!=-1)

{
bytesum+=byteread;
fs.write(buffer,0,byteread);
}
inStream.close();

} catch (Exception e)
{
e.printStackTrace();
}
}
}
package word;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

public class TestDoc
{
public static void main(String args[])
{
int bytesum=0;
int byteread=0;
InputStream inStream;
try
{
inStream = new FileInputStream("c:/1.xls");
FileOutputStream fs=new FileOutputStream("d:/aaa.xls");byte[] buffer =new byte[1444];
while ((byteread=inStream.read(buffer))!=-1) 
{
bytesum+=byteread;
fs.write(buffer,0,byteread);
}
inStream.close(); 
} catch (Exception e)
{
e.printStackTrace();
}
}
}
本文提供了一个使用Java进行文件复制的简单示例。通过InputStream读取源文件,并使用FileOutputStream将内容写入目标文件,实现了从c:/1.xls到d:/aaa.xls的文件复制。

被折叠的 条评论
为什么被折叠?



