8:19 pm - Saturday April 20, 2019

Author Archives: veera

Java Program used to find the parent Directory of the mentioned file using getParent() method.

BACK Get Parent program to find the parent Directory of the mentioned file. Example Program package service1; import java.io.File; public class GetParent { public static void main(String[] args) { File f = null; String v; boolean...

Java Program used to get the name of the file or directory mentioned in pathname using getName() method.

BACK String Getname program to get the name of the file or directory mentioned in pathname. Example Program package service1; import java.io.File; public class StrGetname { public static void main(String[] args) { File f = null; File...

Java Program get totalspace program to get size of a partition where abstract file exists using getTotalSpace() method

BACK Get totalspace program to get size of a partition where abstract file exists. Example Program package service1; import java.io.File; public class TotalSpace { public static void main(String[] args) { File f = null; long...

Java Program is used for memory optimization. It trims the capacity ofArrayList to the current list size using trimToSize() method

  BACK Java ArrayList trimToSize() Method exampletrimToSize() method is used for memory optimization. It trims the capacity ofArrayList to the current list size. Example Program import java.util.ArrayList; public class Trim { public...

Java Program returns an array containing all of the elements in this list in proper sequence (from first to last element) using T[] toArray(T[] a) method

BACK                  The java.util.ArrayList.toArray(T[]) method returns an array containing all of the elements in this list in proper sequence (from first to last element). Example Program import java.util.ArrayList; public...

Java Program returns an array containing all of the elements in this collection using Object[] toArray() method

BACK   Returns an array containing all of the elements in this collection. If the collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. Example...

Return View of the portion of the List

BACK   The subList(int fromIndex,int toIndex) method is used to return a view of the portion of this List between fromIndex, inclusive, and toIndex, exclusive. The returned List is backed by this List, so changes in the returned List are...

Returns the number of unallocated bytes in the partition named by this abstract path name using long getFreeSpace()

BACK           These methods are useful when we want to write some data on disk and need to know howgetFreeSpace provides the available free space EXAMPLE PROGRAM import java.io.File; public class LongFreeSpace { public...

This Program displays the absolute path of the file using getAbsoluteFile() method

BACK   Displays the absolute path of the file. All ‘.’ and ‘..’ references will be resolved. EXAMPLE PROGRAM import java.io.*; public class GetCanonicalPath { public static void main(String[] args) { try...

This Program returns the canonical form of this abstract pathname using getCanonicalFile() method

BACK   The java.io.File.getCanonicalFile() method returns the canonical form of this abstract pathname. EXAMPLE PROGRAM import java.io.*; public class CanonicalFile { public static void main(String[] args) { try { // Open...

This Program will give you the full complete path name (filepath + filename) of a file using File.getAbsolutePath() method.

BACK   The java.io.File.getAbsolutePath() method returns the absolute pathname string of this abstract pathname. EXAMPLE PROGRAM import java.io.File; import java.io.IOException; public class AbsoluteFilePath { public static void...

This Program How to create a new File object by calling getAbsoluteFile() method

BACK It appears that new File(this.getAbsolutePath()) should not be interpreted as being equivalent toinvoking getAbsoluteFile(). EXAMPLE PROGRAM import java.io.*; public class Program { public static void main(String[] args) { //...

Program is used to tests the existence of the file or directory defined by this abstract pathname. Boolean Exist()

BACK   The java.io.File.exists() method tests the existence of the file or directory defined by this abstract pathname. EXAMPLE PROGRAM import java.io.File; public class BooleanExistMethod { public static void main(String[] args)...

Program used to returns true object using Boolean equals(Object obj) method

BACK   The java.lang.Boolean.equals(Object obj) returns true if and only if the argument is not null and is a Boolean object that represents the same boolean value as this object. EXAMPLE PROGRAM public class BooleanEqualsbyObject...

Program is used to deletes the file or directory defined by the abstract path name using Void deleteOnExit()

BACK   The java.io.File.deleteOnExit() method deletes the file or directory defined by the abstract path name when the virtual machine terminates. Files or directories are deleted in the reverse order as they are registered. EXAMPLE PROGRAM import...

Program used to delete the files or directory using Boolean Delete() method

BACK   The java.io.File.delete() method deletes the file or directory defined by the abstract path name. To delete a directory, the directory must be empty. EXAMPLE PROGRAM import java.io.File; public class BooleanDelete { public...

Program for Creating StaticFile createTempFile(String prefix,String suffix,File directory)

BACK   The java.io.File.createTempFile(String prefix, String suffix, File directory)    method creates a new empty file in the specified directory. EXAMPLE PROGRAM import java.io.File; public class CreatTempFile { public...

The Collection Program Sorts the specified list into ascending order, according to the natural ordering of its elements using sort(List list)

BACK   Sorts the specified list into ascending order, according to the natural ordering of its elements. Example Program import java.util.*; public class Sort { public static void main(String[] args) { { List<String> col...

The Collection Program Silgleton Returns an immutable set containing only the specified object using singleton(T o) method

BACK   Returns an immutable set containing only the specified object. It restricts the instantiation of a class to one object. Example Program public class Singleton { private static Singleton sing = new Singleton(); /* * A...

The Collection Program Singleton used to return an immutable list containing only the specified object using SingletonList(T o) method

BACK   The singletonList(T) method is used to return an immutable list containing only the specified object. Example Program import java.util.*; public class List111 { public static void displayList(List<String> l) { Iterator<String>...