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(); } }