首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

InputStream变换为File

2012-11-04 
InputStream转换为FileInputStream ins (new AnnexXML()).getClass().getResourceAsStream(../../annex

InputStream转换为File

InputStream ins = (new AnnexXML()).getClass().getResourceAsStream("../../annexInternet.xml");
???File f=new File("annexInternet.xml");

?inputstreamtofile(ins, f);

?

public static void inputstreamtofile(InputStream ins,File file) {
??try {
???OutputStream os = new FileOutputStream(file);
???int bytesRead = 0;
???byte[] buffer = new byte[8192];
???while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
????os.write(buffer, 0, bytesRead);
???}
???os.close();
???ins.close();
??} catch (Exception e) {
???e.printStackTrace();
??}
?}

热点排行