日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

FileInputStream与FileOutputStream 复制文件例子代码

發(fā)布時(shí)間:2025/3/15 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 FileInputStream与FileOutputStream 复制文件例子代码 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
FileInputStream與FileOutputStream 復(fù)制文件例子代碼 try {File sourceFile = new File("C:\\Users\\prize\\Desktop\\Demo1\\盜墓筆記7.txt");//創(chuàng)建源文件InputStream inputStream = new FileInputStream(sourceFile);//創(chuàng)建輸入文件流BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); //創(chuàng)建文本行緩存輸入流 導(dǎo)入 緩存輸入流File targetFile = new File("F:\\手機(jī)T卡資料\\直接復(fù)制T卡\\EBOOK\\復(fù)制的書.txt"); //創(chuàng)建復(fù)制的目標(biāo)文件if (targetFile.exists()) { //判斷文件是否存在targetFile.delete(); //刪除文件targetFile.createNewFile(); //創(chuàng)建文件}else {targetFile.createNewFile(); }OutputStream out = new FileOutputStream(targetFile); //創(chuàng)建輸出文件流BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); //創(chuàng)建文本緩存輸出流 導(dǎo)入 緩存輸出流String aString = null; //給一行的內(nèi)容準(zhǔn)備的Stringint i = 0;while ((aString = reader.readLine()) != null && i<20) { //讀取一行,并且賦值給aString,然后在判斷不是空值//i++; //此處是為了輸出指定數(shù)量行數(shù)寫的 循環(huán)自增,writer.write("\r\n"+aString); //將內(nèi)容添加到輸出流中//System.out.println(aString);}writer.flush(); //刷新輸出流writer.close(); //關(guān)閉流 ,注意流的關(guān)閉順序out.close();reader.close();inputStream.close();} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}


批量處理文件:


public void fileList() {File inFile = new File("C:\\Users\\lenovo\\Desktop\\copy\\color");File [] files = inFile.listFiles();for (int i = 0; i < files.length; i++) {files[i].delete();System.out.println(files[i].toString());}
posted on 2018-03-26 13:43?觀心靜 閱讀(...) 評(píng)論(...) 編輯 收藏

轉(zhuǎn)載于:https://www.cnblogs.com/guanxinjing/p/9708641.html

總結(jié)

以上是生活随笔為你收集整理的FileInputStream与FileOutputStream 复制文件例子代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。