现在的位置: 首页 > 综合 > 正文

POI操作隐藏的Excel

2017年10月26日 ⁄ 综合 ⁄ 共 467字 ⁄ 字号 评论关闭

JAVA中,当文件隐藏时FileOutputStream 将不可用,可采用RandomAccessFile来操作文件,但是POI的write函数参数只能是OutputStream,参考了网上的一种方法解决:

public final class HiddenFileOutStream extends OutputStream { 
        private final RandomAccessFile _raf; 
        public HiddenFileOutStream(File f) throws FileNotFoundException { 
                _raf = new RandomAccessFile(f, "rw"); 
        } 
        public void write(int b) throws IOException { 
                _raf.write(b); 
        } 
        public void write(byte[] b, int off, int len) throws IOException { 
                _raf.write(b, off, len); 
        } 
        public void close() throws IOException { 
        	_raf.close();
        } 
} 

抱歉!评论已关闭.