java如何检查文件状态,可读,可写?

rf_wu 2005-07-22 02:44:31

如何检查文件状态,
可读
可写
还有已经如何检查这个文件已经在使用中了?

java.io.File这个对象里好象没有?

谢谢
...全文
468 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuxinqi 2005-07-26
  • 打赏
  • 举报
回复
file.canRead()和file.canWrite()应该是判断该文件的属性,不能判断该文件是否被其它程序锁住。所以好像只能用异常来处理。不知我的想法对否。
huangdeji 2005-07-26
  • 打赏
  • 举报
回复
File file = new File();
file.canRead( );
file.canWrite( );
至于你说的判断这个文件是不是正在使用中,是不是可以用异常来判断呢?
有待调查。
homesos 2005-07-26
  • 打赏
  • 举报
回复
java.lang.Object
|
+--java.io.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.

more...
interhanchi 2005-07-22
  • 打赏
  • 举报
回复
canRead()
和 canWrite().
hcom 2005-07-22
  • 打赏
  • 举报
回复
up
mustdobetter 2005-07-22
  • 打赏
  • 举报
回复
学习
laughsmile 2005-07-22
  • 打赏
  • 举报
回复
1.java.io.File.canRead()
2.java.io.File.canWrite()
3.java.nio.channels.FileLock
jsjzzh 2005-07-22
  • 打赏
  • 举报
回复
import java.io.*;
File f=new File("file.txt");

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.

boolean isHidden()
Tests whether the file named by this abstract pathname is a hidden file.

long lastModified()
Returns the time that the file denoted by this abstract pathname was last modified.

boolean setLastModified(long time)
Sets the last-modified time of the file or directory named by this abstract pathname.

boolean setReadOnly()
Marks the file or directory named by this abstract pathname so that only read operations are allowed.
cy_angel 2005-07-22
  • 打赏
  • 举报
回复
试一试这两个方法,可以得到文件的读写状态:
File f = new File();
f.canRead( );
f.canWrite( );
mofeir 2005-07-22
  • 打赏
  • 举报
回复
没有/。
shloshlo 2005-07-22
  • 打赏
  • 举报
回复
再找找,有。

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧