Share on Google+Share on Google+

Writing ISO Latin-1 Encoded Data in Java

Advertisement
In this program, you will see how to write content in a file in the ISO Latin-1 character set.

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.

Advertisements

Posted on: April 17, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.

Comments:1
Coralie
November 1, 2011
rIYlfkLTHesm

The purchases I make are entirely based on these atircles.