Home Java Network EncoderTest
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

EncoderTest

Advertisement
This is a simple program of java network and supports the java.net package. Here, we have defined the class named EncoderTest.java. This class contains static methods for converting a String to the application-urlencoded MIME format.

EncoderTest

     

This is a simple program of java network and supports the java.net package. Here, we have defined the class named EncoderTest.java. This class contains static methods for converting a String to the application-urlencoded MIME format.

The alphanumeric characters "a" through "z", "A" through "Z" and "0" through "9" remain the same. And the space characters ".", "-", "*", and "_" remain the same. The encoding string supports to the space character ? ? is converted into a plus sign ?+?. All other characters are unsafe and are first converted into one or more bytes using some encoding scheme. 


Here is the code of this program:

import java.net.*;
import java.net.URLEncoder;

public class EncoderTest{
  public static void main(String[] args){
    System.out.println(URLEncoder.encode("This string has spaces"));
    System.out.println(URLEncoder.encode("This*string*has*stars"));
    System.out.println(URLEncoder.encode("This%string%has%percent%signs"));
    System.out.println(URLEncoder.encode("This.is.first.program.of.encoder"));
    System.out.println(URLEncoder.encode("This/is/simple/Encoder/test/program"));
  }
}


Output of this program:

C:\amar>javac EncoderTest.java

C:\amar>java EncoderTest
This+string+has+spaces
This*string*has*stars
This%25string%25has%25percent%25signs
This.is.first.program.of.encoder
This%2Fis%2Fsimple%2FEncoder%2Ftest%2Fprogram

C:\amar>

 

Download of this program.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  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.

Posted on: March 19, 2008

Related Tutorials

Ask Questions?    Discuss: EncoderTest  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com