- package org.jr.io;
- /**
- * Copyright: Copyright (c) 2002-2004
- * Company: JavaResearch(http://www.javaresearch.org)
- * 最后更新日期:2004年8月31日
- * @author Cherami
- */
- import java.io.*;
- /**
- * 此类中封装一些常用的写文件操作。
- * 所有方法都是静态方法,不需要生成此类的实例,
- * 为避免生成此类的实例,构造方法被申明为private类型的。
- * @since 0.6
- */
-
- public class FileWriter {
- /**
- * 私有构造方法,防止类的实例化,因为工具类不需要实例化。
- */
- private FileWriter() {
- }
- /**
- * 从指定的文件中读取一个序列化的对象。
- * @param filename 文件名
- * @return 序列化文件对应的对象,有任何错误返回null。
- * @since 0.6
- */
- public static void writeObject(String filename,Object object) {
- ObjectOutputStream out=null;
- try {
- out=new ObjectOutputStream(new FileOutputStream(filename));
- out.writeObject(object);
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- if (out!=null) {
- try {
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- }