Number of View: 184
When the data was written to disk, certain information was lost, such as the type of each value. For example, if the value
"10" is read from a file, there’s no way to tell whether it came from an
String or a
double. We have only data, not type information, on a disk.
we want to read an object from or write an object to a file or over a network connection. Java provides a concept called serialization for this purposes. Continue reading
Number of View: 245
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: 179
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: 439
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: 650
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