首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java-字符输入流读取资料时的字符数组的使用

2012-09-14 
java-字符输入流读取文件时的字符数组的使用public static void main(String[] args) throws Exception {F

java-字符输入流读取文件时的字符数组的使用

public static void main(String[] args) throws Exception {FileReader fr = new FileReader("c:\\test.txt");// test.txt中内容1234567890char[] cs = new char[4];int count = 0;while ((count = fr.read(cs)) > 0) {for (int i = 0; i < count; i++) {System.out.println(cs[i]);}}}



Java实现文件复制
public void fileCopy(String filePath,String savePath){       try{                      FileInputStream in = new FileInputStream(filePath);           FileOutputStream out = new FileOutputStream(savePath);           byte[] bt = new byte[1024];           int count;                 while ((count = in.read(bt)) > 0) {                     out.write(bt, 0, count);  //重点              }                 in.close();                 out.close();          }catch(IOException e){           e.printStackTrace();       }   }  

热点排行