文件输入的例子。

来源:互联网 发布:开盘摇号软件 编辑:程序博客网 时间:2024/05/01 22:06
import java.io.File;import java.io.FileOutputStream;import java.io.IOException;public class iofiles {/** * @param args * @throws IOException  */public static void main(String[] args)  {FileOutputStream fos=null;try {File dir = new File("E:\\tempfile");if (!dir.exists()) {dir.mkdir();} fos = new FileOutputStream("E:\\tempfile\\2.txt",true);String str = "guiling";/*byte[] buf = str.getBytes();fos.write(buf);*/fos.write(str.getBytes());fos.close();} catch (Exception e) {System.out.println(e.toString()+"--");}finally{if(fos!=null){try {fos.close();} catch (IOException e) {throw new  RuntimeException(""+e);}}}}}

0 0
原创粉丝点击