- 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 34494 Articles for Programming
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
239 Views
You can access a plain text using the File class.ExampleLive Demoimport java.io.File; public class ReadFile { public static void main(String[] args) { File f = null; String str = "data.txt"; try { f = new File(str); boolean bool = f.canExecute(); String a = f.getAbsolutePath(); System.out.print(a); System.out.println(" is executable: "+ bool); } catch (Exception e) { e.printStackTrace(); } } }Output C:\Users\data is executable: true
![Sai Subramanyam](https://www.tutorialspoint.com/assets/profiles/13512/profile/60_68191-1512710774.jpg)
2K+ Views
You can create a PDF file using the PDF Box library. You can set the environment for pdf box by following Pdf Box Environment Tutorial. Example import java.io.IOException; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; public class CreatingEmptyPdf { public static void main(String args[]) throws IOException { PDDocument document = new PDDocument(); document.addPage(new PDPage()); document.save("C:/pdfBox/BlankPdf.pdf"); System.out.println("PDF created"); document.close(); } } Output PDF created
![Monica Mona](https://www.tutorialspoint.com/assets/profiles/13520/profile/60_87298-1512650151.jpg)
170 Views
File class provides various methods to perform respective file operations.canRead(): This method tests whether the application can read the file denoted by this abstract pathname. It returns true if and only if the file specified by this abstract pathname exists and can be read by the application; false otherwise.canWrite(): This method tests whether the application can modify the file denoted by this abstract pathname. It returns true if and only if the file system actually contains a file denoted by this abstract pathname and the application is allowed to write to the file; false otherwise.createNewFile(): This method atomically creates a ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
74 Views
You can sort an array using sort() method of the Arrays class.ExampleLive Demoimport java.util.Arrays; public class MainClass { public static void main(String args[]) throws Exception { int array[] = { 2, 5, -2, 6, -3, 8, 0, -7, -9, 4 }; Arrays.sort(array); printArray("Sorted array", array); int index = Arrays.binarySearch(array, 1); System.out.println("Didn't find 1 @ " + index); int newIndex = -index - 1; array = insertElement(array, 1, newIndex); printArray("With 1 added", array); } ... Read More
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
1K+ Views
You can get the size of a directory with the help of FileUtils.sizeofDirectory(File Name) method of FileUtils class.Exampleimport java.io.File; import org.apache.commons.io.FileUtils; public class Main { public static void main(String[] args) { long size = FileUtils.sizeOfDirectory(new File("C:/Windows")); System.out.println("Size: " + size + " bytes"); } }OutputSize: 2048 bytes
![Swarali Sree](https://www.tutorialspoint.com/assets/profiles/13515/profile/60_84115-1512649510.jpg)
102 Views
Following example shows the way to look for a particular file in a directory by creating a File filter. Following example displays all the files having file names beginning with 'b'.ExampleLive Demoimport java.io.*; public class Main { public static void main(String[] args) { File dir = new File("C:"); FilenameFilter filter = new FilenameFilter() { public boolean accept (File dir, String name) { return name.startsWith("b"); } }; String[] children = ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
191 Views
The java.io.File.mkdirs() creates the directory named by this abstract pathname, together with necessary and non-existent parent directories.ExampleLive Demoimport java.io.File; public class Main { public static void main(String[] args) { String directories = "D:\a\b\c\d "; File file = new File(directories); boolean result = file.mkdirs(); System.out.println("Status = " + result); } }OutputStatus = true
![Rajendra Dharmkar](https://www.tutorialspoint.com/assets/profiles/9963/profile/60_124173-1512724240.jpg)
297 Views
The following code splits given string by a period and a line break as followsExampleimport re s = """Hi. It's nice meeting you. My name is Jason.""" result = re.findall(r'[^\s\.][^\.]+', s) print resultOutputThis gives the following output['Hi', "It's nice meeting you", 'My name is Jason']
![Monica Mona](https://www.tutorialspoint.com/assets/profiles/13520/profile/60_87298-1512650151.jpg)
96 Views
The file class provides a method named exists() which returns true if the file specified in the current file object exists.ExampleLive Demoimport java.io.File; public class FileHandling { public static void main(String args[]) { File file = new File("samplefile"); if(file.exists()) { System.out.println("Given file existed"); } else { System.out.println("Given file does not existed"); } } }OutputGiven file does not existed
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
773 Views
You can get the list of files in a directory −Create a directory object using the File class.Get the list of directories in it using the getName() method.Exampleimport java.io.File; public class FindingDirectories { public static void main(String args[]) { String dir ="C:/Users/Tutorialspoint/Desktop/movies"; File directory = new File(dir); File[] fileList = directory.listFiles(); for(File file: fileList) { System.out.println(file.getName()); } } }OutputArundhati HD.mp4 Okka Ammai Tappa.mkv Padamati Sandhya Ragam.mp4