java读取隐藏文件的问题

    xiaoxiao2021-03-25  65

    碰到一个有点坑的问题:当我创建了一个隐藏的文件后,然后下次在读取这个文件追加时,一直是拒绝访问的错误

    public static File createHideFile(String okr){ File file = new File(okr);           try {         if(!file.exists()){         file.createNewFile();                   // R : 只读文件属性。A:存档文件属性。S:系统文件属性。H:隐藏文件属性。                   String sets = "attrib +H \"" + file.getAbsolutePath() + "\"";                   // 运行命令                   Runtime.getRuntime().exec(sets);          }         } catch (IOException e) {               e.printStackTrace();           }          return file; }

    解决方法:

    RandomAccessFile f = new RandomAccessFile(file, "rw"); f.write("admin".getBytes()); f.write(":".getBytes()); f.write("1234516".getBytes()); f.seek(0); System.out.println(f.readLine()); f.close();

    说下seek()方法:是将指针移动到指定位置,一般是多少个字节。

    转载请注明原文地址: https://ju.6miu.com/read-16280.html

    最新回复(0)