java速学教程(入门到精通)
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
1、使用FileInputStream、FileOutputStream完成文件的复制
public void fileCapy(String src, String dest) { FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(new File(src)); fos = new FileOutputStream(new File(dest)); byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) != -1) { fos.write(bytes, 0, length); } } catch (IOException e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } if (fis != null) { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } } }
2、使用FileReader、 FileWriter完成文本的复制(对于非文本文件, 只能使用字节流)
public void textCapy(String src, String dest) { FileReader fr = null; FileWriter fw = null; try { fr = new FileReader(new File(src)); fw = new FileWriter(new File(dest)); char[] chars = new char[1024]; int length; while ((length = fr.read(chars)) != -1) { fw.write(chars, 0, length); } } catch (IOException e) { e.printStackTrace(); } finally { if (fw != null) { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } if (fr != null) { try { fr.close(); } catch (IOException e) { e.printStackTrace(); } } } }
Java免费学习笔记:立即学习
解锁 Java 大师之旅:从入门到精通的终极指南
已抢6717个
抢已抢90861个
抢已抢14323个
抢已抢50399个
抢已抢189616个
抢已抢86052个
抢