home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 March
/
Chip_2002-03_cd1.bin
/
internet
/
kosek
/
sw
/
convert
/
Convert.java
< prev
next >
Wrap
Text File
|
2000-11-01
|
1KB
|
62 lines
import java.io.*;
public class Convert
{
public static void main(String[] args)
{
String l = "";
try
{
if (args.length < 2)
{
System.out.println("Usage: java Convert <infile> <outfile>");
System.exit(1);
}
BufferedReader in = new BufferedReader(new FileReader(args[0]));
BufferedWriter out = new BufferedWriter(new FileWriter(args[1]));
while ((l = in.readLine()) != null)
{
out.write(convert(l) + "\n");
}
in.close();
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
private static String toHex (int i)
{
String s;
s = Integer.toHexString(i);
while (s.length() < 4) s = "0" + s;
return s;
}
private static String convert (String s)
{
String t = "";
for (int i=0; i<s.length(); i++)
{
if ((int)s.charAt(i) > 127)
{
t += "" + toHex((int)s.charAt(i)) + ";";
}
else
t += s.charAt(i);
}
return t;
}
}