如何用JAVA写只读文件
比如文件D:\11.txt为只读,如何用程序去实现写这个文件,请指点,谢谢
------解决方案--------------------package test;
import java.io.File;
import java.io.FileWriter;
import
java.io.IOException;
import java.io.PrintWriter;
public class test1
{
public static void main(String[] args) throws
IOException {
File f = new File( "D:\\11.txt ");
if(!f.canWrite())
f.setWritable(true);
PrintWriter writer = new PrintWriter(new FileWriter(f));
writer.write( "www.csdn.net ");
writer.close();
f.setWritable(false);
}
}
// 以上代码 针对java 1.6