- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 4336 Articles for Java 8
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
75 Views
The method java.io.File.getUsableSpace() is used to obtain the usable space in the form of bytes for the virtual machine on the partition specified by the required abstract path name. This method requires no parameters and it returns the bytes for the virtual machine on the partition.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { File[] roots = File.listRoots(); try { for(File r : roots) { System.out.println(r); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
281 Views
The method java.io.File.getFreeSpace() is used to obtain the free space in the form of unallocated bytes for the partition specified by the required abstract path name. This method requires no parameters and it returns the unallocated bytes for the partition.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { File[] roots = File.listRoots(); try { for(File r : roots) { System.out.println(r); System.out.println("Free space = " + r.getFreeSpace()); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
256 Views
The method java.io.File.listRoots() is used to list the file system roots in Java. This method requires no parameters. It returns the available file system roots in the form of an array of file objects and if the file system roots cannot be determined, it returns null.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { File[] roots = File.listRoots(); try { for(File r : roots) { System.out.println(r); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
The attribute of a file can be changed to read-only by using the method java.io.File.setReadOnly(). This method requires no parameters and it returns true if the file is set to read-only and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { boolean flag; try { File file = new File("demo1.txt"); file.createNewFile(); flag = file.setReadOnly(); System.out.println("File is read-only?: " + flag); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
88 Views
A file can be set to read-only by using the method java.io.File.setReadOnly(). This method requires no parameters and it returns true if the file is set to read-only and false otherwise. The method java.io.File.canWrite() is used to check whether the file can be written to in Java and if not, then the file is confirmed to be read-only.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { boolean flag; try { File file = new File("demo1.txt"); ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
160 Views
A file or directory with the required abstract pathname can be deleted when the program ends i.e. after the virtual machine terminates using the method java.io.File.deleteOnExit(). This method requires no parameters and it does not return a value.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { try { File file = new File("demo1.txt"); file.createNewFile(); System.out.println("File: " + file); file.deleteOnExit(); } catch(Exception e) { ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
94 Views
The java.io.File class has display constants File.separatorChar and File.pathSeparatorChar mainly. The File.separatorChar is ‘/’ and the File.pathSeparatorChar is ‘:’ for Unix.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { try { System.out.println("File.pathSeparatorChar = " + File.pathSeparatorChar); System.out.println("File.separatorChar = " + File.separatorChar); } catch(Exception e) { e.printStackTrace(); } } }The output of the above program is as follows −OutputFile.pathSeparatorChar = : File.separatorChar = /Now let ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
10K+ Views
A new empty file with the required abstract path name can be created using the method java.io.File.createNewFile(). This method requires no parameters and it returns true if the file is newly created and it did not exist previously. If the file existed previously, it returns false.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { try { File file = new File("demo1.txt"); file.createNewFile(); System.out.println("File: " + file); } catch(Exception ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
703 Views
A directory can be created with the required abstract path name using the method java.io.File.mkdir(). This method requires no parameters and it returns true on the success of the directory creation or false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { try { File file = new File("c:\demo1\"); file.createNewFile(); boolean flag = file.mkdir(); System.out.print("Directory created? " + flag); } catch(Exception e) { ... Read More
![Naveen Singh](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
2K+ Views
The method java.io.File.renameTo() is used to rename a file or directory. This method requires a single parameter i.e. the name that the file or directory is renamed to and it returns true on the success of the renaming or false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) { try { File file1 = new File("demo1.txt"); File file2 = new File("demo2.txt"); file1.createNewFile(); file2.createNewFile(); ... Read More