Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How java copies files through character buffer streams

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how java copies files through the character buffer stream, which is very detailed and has a certain reference value. Interested friends must finish reading it!

Copy a file through a character buffer stream

Character buffer streams can only read text files

/ * * copy files through character buffer stream * * @ param sourcePath source file path * @ param targetPath destination file path * / public static void copyFileByBufferedChar (String sourcePath, String targetPath) {/ / source file path File source = new File (sourcePath); / / destination file path File target = new File (targetPath) / / cannot copy if (! source.exists ()) {return;} / / if the source file does not exist, create if (! target.getParentFile (). Exists ()) {target.getParentFile (). Mkdirs ();} BufferedReader in = null; BufferedWriter out = null if the destination file directory does not exist Try {/ / character buffer input stream and character buffer output stream in = new BufferedReader (new FileReader (source)); out = new BufferedWriter (new FileWriter (target)); / / read file (one line at a time) String temp = null; while ((temp = in.readLine ())! = null) {/ / output to file out.write (temp) }} catch (Exception e) {e.printStackTrace ();} finally {/ / close stream try {if (in! = null) {in.close ();} if (out! = null) {out.close ();}} catch (IOException e) {e.printStackTrace () } this is all the content of the article "how java copies files through character buffer streams". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report