单例模式 异常抛出

public class FileUtil {

    private static class SingleFileUtill{
        private static FileSystem fs = null;
        static{
            fs = SingleFileUtill.getInstance();
        }

        private static FileSystem getInstance(){
            Configuration conf = new Configuration();
            FileSystem fs = null;
            try {
                fs = FileSystem.get(conf);
                return fs;
            } catch (IOException e) {
                e.printStackTrace();
            }
            return fs;
        }

    }
    public static FileSystem getFileSystem(){
        return SingleFileUtill.fs;
    }
}
原文地址:https://www.cnblogs.com/cunchen/p/9464194.html