Home Tutorial Java Core Files Java file encoding

 
 

Java file encoding
Posted on: June 17, 2006 at 12:00 AM
Advertisement
In this section, you will learn how to get the file encoding.

Java file encoding

In this section, you will learn how to get the file encoding.

Description of code:

An encoding is a mapping between a byte value and its representation. It describes how characters are represented as bytes in files. In the given example, we have used InputStreamReader class that wraps the input stream and called its method getEncoding() which returns the desired encoding of the file.

Here is the code:

import java.io.*;

public class FileEncoding {
	public static void main(String[] args) throws Exception {
		File in = new File("C:/file.txt");
		InputStreamReader r = new InputStreamReader(new FileInputStream(in));
		System.out.println(r.getEncoding());
	}
}
Advertisement

Related Tags for Java file encoding:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 17, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com