当前位置导航:炫浪网>>网络学院>>编程开发>>JAVA教程>>Java入门

java.io.File写入写出的一个简单实例

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestIO {

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
byte[] b = new byte[17*1024];
// ** txt
// File f = new File("d:\\test.txt");
// File outF = new File("d:\\testOut.txt");
// ** jpg
File f = new File("d:\\毫无保留.jpg?http://www.xvna.com");
File outF = new File("d:\\毫无保留Output.jpg?http://www.xvna.com");
try
{
FileInputStream fis = new FileInputStream(f);
FileOutputStream fops = new FileOutputStream(outF);
fis.read(b);
fops.write(b);

// ** for see
// String s = new String(b);
// System.out.println(s);

fis.close();
fops.close();
}
catch(FileNotFoundException fnfe)
{
System.out.println("FileNotFoundException fnfe");
fnfe.printStackTrace();
}
catch(IOException ie)
{
System.out.println("IOException ie");
ie.printStackTrace();
}


}

}
相关内容
赞助商链接