kita akan mencoba merubah atribut file "newfile.txt" yang berada pada direktori "C:\\"
berikut ini contoh programnya
Nama file : contoh_SetReadOnly.java
import java.io.File;
import java.io.IOException;
public class contoh_SetReadOnly {
public static void main(String[] args) throws IOException
{
File myfile = new File("C://newfile.txt");
//making the file read only
boolean flag = myfile.setReadOnly();
if (flag==true)
{
System.out.println("File successfully converted to Read only mode!!");
}
else
{
System.out.println("Unsuccessful Operation!!");
}
}
}
Output
run:
File successfully converted to Read only mode!!
BUILD SUCCESSFUL (total time: 19 seconds)
program dibuat menggunakan netbeans
selamat mencoba, semoga bermanfaat ...
No comments:
Post a Comment