关于文件与文件流!
大侠:
如何在Java中判断一文件的读写属性,如要判断C:/dtd.txt是否是只读,
如是只读,将它改为可写!(代码如何写)
望大侠指点,万分感激!!!!!!!!!!
问题点数:0、回复次数:4Top
1 楼mvmouse(mouse)回复于 2004-04-02 13:51:22 得分 0
关注,顶一下Top
2 楼muymuy(muy)回复于 2004-04-02 14:19:08 得分 0
用File.canWrite();和File.calRead();
File file = new File("c:\dtd.txt");
if (file.canWrite()
System.out.println("可写");
if (file.canRead())
System.out.println("可读");
Top
3 楼bigcrazy(大疯狂)回复于 2004-04-02 14:19:39 得分 0
File类有这两个方法。
boolean canRead()
Tests whether the application can read the file denoted by this abstract pathname.
boolean canWrite()
Tests whether the application can modify to the file denoted by this abstract pathname.
有个FilePermission类不知道能不能满足你的要求。自己多写点程序试试吧。
Top
4 楼muymuy(muy)回复于 2004-04-02 14:36:01 得分 0
File里有个方法:File.setReadOnly();
可以将文件属性设置为只读,但是反过来,将只读改为可写,这个方法好像还没有,至少我还没有发现。Top




