Number of View: 117
Java 7 added a new construct called try-with-resources.
To understand try with resources we need to understand how resources are handled before java7.Before
Java 7, when we worked with a resource, such as a file, a SQL statement, etc., you had to use a finally
block and write a few lines of boilerplate code to close the resource.
Number of View: 70
Static import :
Static import is used to import static members of class or interface.To refer static members directly without using class name we use static import.
static import declarations import only
static class members. Continue reading
Number of View: 389
Java File Permissions example
To set the read permissions to a file from java code use setReadable method of File class to true or false.
To set the write permissions to a file from java code use setWritable method of File class to true or false. Continue reading
Number of View: 513
File.separator is used to obtain the local computer’s proper separator character instead of explicitly using / or \. For example On a Windows computer, the separator character is a backslash (\).
On a Linux or Mac OS X system, it’s a forward slash (/).
File.separator is a String consisting of one character—the proper separator for the system. Continue reading
Number of View: 398
Write a java program to create new file in java?
File is created using java.io.File class.File Object contains information about file but it doesnot create new file.
The below line creates a new file object but it does not create a file in C drive.
File file=new File(“c:\\File1.txt”); Continue reading