What to do when your body tag in html doesn’t accept lessthan or greaterthan tag

Posted on Updated on

Few days back one of my friend developed a website and he got this this problem.Finally he came up with a solution. In general if you want ‘< ‘or ‘>’ symbol in the body of you web page you need to replace it with “&lt”.Imagine if you have lot of them in your body,you cant replace them manually right.So my friend decided to write a program that automatically substitutes “&lt” for ‘<‘ or ‘>’ symbol. After seeing that i was excited and decided to publish this as a post for you people.hope it might help some of you….

Here is the code…

import java.io.*;

/**
*
* @author pavan
*/

public class Tests {

/**
* @param args the command line arguments
*/

public static void copy(File source, File target) throws IOException {

//InputStream in = new FileInputStream(source);
//DataInputStream in = new DataInputStream(source);
FileInputStream br = new FileInputStream(source);

OutputStream out = new FileOutputStream(target);

// Copy the bits from instream to outstream
byte[] buf = new byte[1024];
String str;
int len;

while ((len = br.read()) &gt; 0) {

if((char)len==’&lt;’)
{
len=’&’;
out.write(len);
len=’l’;
out.write(len);
len=’t’;
out.write(len);
len=’;’;
out.write(len);
}
else if((char)len==’&gt;’)
{
len=’&’;
out.write(len);
len=’g’;
out.write(len);
len=’t’;
out.write(len);
len=’;’;
out.write(len);
}

else
out.write(len);
}

br.close();
out.close();
}
public static void main(String[] args) throws IOException{
// TODO code application logic her
String path = “.”;

String files;
File folder = new File(path);
File[] listOfFiles = folder.listFiles();

for (int i = 0; i &lt; listOfFiles.length; i++)
{

if (listOfFiles[i].isFile())
{
File f2= new File(“cdump/”+listOfFiles[i].getName());
copy(listOfFiles[i],f2);
files = listOfFiles[i].getName();
System.out.println(files);
}
}
}
}

The website in which he has implemented this program is codeinstant.comeze.com. Visit this it will be really useful for you people and you will find it interesting while giving the search query….

Leave a comment