Files and directories in java-lab 2

This post helps you to understand various files methods available.

File currentDirectory = new File(“E:\hai123.txt”);

 System.out.println(currentDirectory.getCanonicalPath());
 System.out.println(currentDirectory.getAbsolutePath());
 System.out.println(currentDirectory.getPath());
 System.out.println(currentDirectory.getParent());

 

Create a temporary file with name and extension. setOut methods helps you to write some contents into the file.

File temp = File.createTempFile("temp_", ".tmp", new File("E:/zip files"));
 
 System.setOut(new PrintStream(temp));
 System.out.println("hai how r u!!!!");

Hope this helps. Please subscribe and comment about this post.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s