IO流
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\\administratoa\\desktop\\文件接收柜\\\\data.txt"); try{ FileWriter fw=new FileWriter(file,true); FileOutputStream out=new FileOutputStream(file); String str="123qwe@#$软件工程"; for(i=0;i<str.length()-4;i++){ out.write(str.charAt(i)); } for(;i<str.length()-4;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(IOException ioe){ ioe.printStackTrace(); } } }