HOME      BLOG       FORUMS      CONTACT       ABOUT

Tests whether a file is readable or not.

May 27th, 2008 Albin Joseph Posted in java.io No Comments »

The canRead method of file class can be used for checking whether the application has a read permission on a file.

package io;

import java.io.File;

public class FileExample {
	public static void main(String[] args){
		File file = new File("d:\\temp\\test.txt");

		boolean value = file.canRead();
		System.out.println(value);
	}
}
Share
AddThis Social Bookmark Button

Converts a file object to a URI object.

May 13th, 2008 Albin Joseph Posted in java.io No Comments »

Converts a file object to a URI object.

The toURI method of file class can be used for converting a file object to a URI object.

package io;

import java.io.File;
import java.net.URI;

public class FileExample {
	public static void main(String[] args){
		File file = new File("text.txt");

		URI uri = file.toURI();
		System.out.println(uri);
	}
}
Share
AddThis Social Bookmark Button

Converts a file object to a URL object.

May 13th, 2008 Albin Joseph Posted in java.io No Comments »

Converts a file object to a URL object.

In order to convert a file object to a URL object, we first need to convert the file object to a URI object. Then by calling the toURL method of URI class we can get a URL representation of file object.

package io;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;

public class FileExample {
	public static void main(String[] args) throws MalformedURLException {
		File file = new File("text.txt");

		URI uri = file.toURI();
		URL url = uri.toURL();
		System.out.println(url);
	}
}
Share
AddThis Social Bookmark Button

Finds the absolute path of a file or directory as a file object.

May 13th, 2008 Albin Joseph Posted in java.io No Comments »

Finds the absolute path of a file or directory as a file object.

The getAbsoluteFile method of file class returns the current file object’s absolute path as a file object.

package io;

import java.io.File;

public class FileExample {
	public static void main(String[] args) {
		File file = new File("text.txt");

		File path = file.getAbsoluteFile();
		System.out.println(path);
	}
}
Share
AddThis Social Bookmark Button

Finds the absolute path of a file or directory

May 13th, 2008 Albin Joseph Posted in java.io No Comments »

Finds the absolute path of a file or directory

The getAbsolutePath method of file class is used for finding the absolute path of a directory and directory.

package io;

import java.io.File;

public class FileExample {
	public static void main(String[] args) {
		File file = new File("text.txt");

		String path = file.getAbsolutePath();
		System.out.println(path);
	}
}
Share
AddThis Social Bookmark Button

Checks whether the file path is absolute path or not.

May 13th, 2008 Albin Joseph Posted in java.io No Comments »

Checks whether the file path is absolute path or not.

The isAbsolute method of file class is used for finding whether the given file path is absolute or not.

package io;

import java.io.File;

public class FileExample {
	public static void main(String[] args) {
		File file = new File("d:\\temp\\text.txt");

		boolean isAbsolute = file.isAbsolute();
		System.out.println(isAbsolute);
	}
}
Share
AddThis Social Bookmark Button

Finds the pathname from a file object

May 13th, 2008 Albin Joseph Posted in java.io No Comments »

Finds the pathname from a file object

The getPath method of file class returns the path in string format.

package io;

import java.io.File;

public class FileExample {
	public static void main(String[] args) {
		File file = new File("d:\\temp\\text.txt");

		String path = file.getPath();
		System.out.println(path);
	}
}
Share
AddThis Social Bookmark Button

Find the parent directory of the current directory or file.

May 13th, 2008 Albin Joseph Posted in java.io No Comments »

Find the parent directory of the current directory or file.

The getParent method of file class returns the parent directory of the current file object.

package io;

import java.io.File;

public class FileExample {
	public static void main(String[] args) {
		File file = new File("d:\\temp\\text.txt");

		String parent = file.getParent();
		System.out.println(parent);
	}
}
Share
AddThis Social Bookmark Button

Find the filename or directory name from a file object.

May 13th, 2008 Albin Joseph Posted in java.io No Comments »

Find the filename or directory name from a file object.

The getName method of file class returns the name of the file or directory of the current file object.

import java.io.File;

public class FileExample {
public static void main(String[] args) {
File file = new File("d:\\temp");

System.out.println(file.getName());
}
}
Share
AddThis Social Bookmark Button