package FileHandling;
import java.io.*;
public class FileClassOperations {
public static void fileOrDirectory(File f)
{
if(f.isDirectory())
System.out.println(f.getName()+" is a directory");
else
System.out.println(f.getName()+" is a file");
}
public static void retrieveLength(File f)
{
System.out.println("The length of file is: "+f.length());
}
public static void retrieveFilePath(File f)
{
System.out.println("The Absolute Path of file is: "+f.getAbsolutePath());
System.out.println("The Relative Path of file is: "+f.getPath());
}
public static boolean renameFile(File f,File g)
{
boolean bool=f.renameTo(g);
return bool;
}
public static void setWritePermission(File f)
{
//First argument explains that the file is writable
//And second argument says the permission of owner,if true then only owner
//and if false everybody can write so here every user can write in this file
System.out.println("The file is writable by everyone:"+f.setWritable(true, false));
}
public static void main(String[] args) {
File fl=new File("abhishek.txt");
File gl=new File("abhishek230.txt");
fileOrDirectory(fl);
retrieveLength(fl);
retrieveFilePath(fl);
setWritePermission(fl);
boolean b=renameFile(fl,gl);
System.out.println("File Renamed: "+b);
}
}
import java.io.*;
public class FileClassOperations {
public static void fileOrDirectory(File f)
{
if(f.isDirectory())
System.out.println(f.getName()+" is a directory");
else
System.out.println(f.getName()+" is a file");
}
public static void retrieveLength(File f)
{
System.out.println("The length of file is: "+f.length());
}
public static void retrieveFilePath(File f)
{
System.out.println("The Absolute Path of file is: "+f.getAbsolutePath());
System.out.println("The Relative Path of file is: "+f.getPath());
}
public static boolean renameFile(File f,File g)
{
boolean bool=f.renameTo(g);
return bool;
}
public static void setWritePermission(File f)
{
//First argument explains that the file is writable
//And second argument says the permission of owner,if true then only owner
//and if false everybody can write so here every user can write in this file
System.out.println("The file is writable by everyone:"+f.setWritable(true, false));
}
public static void main(String[] args) {
File fl=new File("abhishek.txt");
File gl=new File("abhishek230.txt");
fileOrDirectory(fl);
retrieveLength(fl);
retrieveFilePath(fl);
setWritePermission(fl);
boolean b=renameFile(fl,gl);
System.out.println("File Renamed: "+b);
}
}
0 comments:
Post a Comment