Writing ISO Latin-1 Encoded Data in Java

Introducton
In this program, you will see how to write content in a file in the
ISO Latin-1
character set. This program takes a
file name, if the given
file exists then writes text into the file otherwise shows the message :
"File
does not exists.".
out.write( )
This is the method is used to write text in the
specified file in the ISO Latin-1 character set. Here, the specified string is
"Welcome to RoseIndia.Net"
which has to be written into the file.
Here is the code of the program :
import java.io.*;
public class WriteEncodedLatin{
public static void main(String[] args)throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter File name : ");
String str = in.readLine();
File file = new File(str);
if(!file.exists())
{
System.out.println("File does not exist");
System.exit(0);
}
else
{
try{
BufferedWriter out = new BufferedWriter(new OutputStreamWriter
(new FileOutputStream(file),"8859_1"));
out.write("WelCome to RoseIndia.Net");
out.close();
System.out.println("Written Process Completed");
}
catch(UnsupportedEncodingException ue){
System.out.println("Not supported : ");
}
catch(IOException e){
System.out.println(e.getMessage());
}
}
}
}
|
Output of the Program:
C:\nisha>javac WriteEncodedLatin.java
C:\nisha>java WriteEncodedLatin
Enter File name : Filterfile.txt
Written Process Completed
C:\nisha> |
Download this example.

|