I/O
2019-06-26 12:21 刘彩程 阅读(284) 评论(0) 编辑 收藏 举报package bbb; import java.io.*; public class ccc { public static void main(String[] args) throws IOException { int i=0; File file=new File("C:\\Users\\Administrator\\Desktop\\文件接收柜\\data.txt"); try { FileWriter fw=new FileWriter(file,true); FileOutputStream out=new FileOutputStream(file); String str = "12345abcdef@#%&*软件工程"; for( i=0;i<str.length()-4;i++) { out.write(str.charAt(i));} for( ;i<str.length();i++) fw.write(str.charAt(i)); out.close(); fw.close(); }catch(Exception e){ e.printStackTrace(); } try{ FileInputStream in=new FileInputStream(file); byte[] buf=new byte[(int)(file.length())]; in.read(buf); String str=new String(buf); System.out.println(str); in.close(); }catch(FileNotFoundException fn){ System.out.println("文件打开失败"); }catch(IOException ioe){ ioe.printStackTrace(); } } }