import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class StreamContendConverter
{
private String m_inputFilePath;
private String m_inputCodePage;
private String m_outputFilePath;
private String m_outputCodePage;
public StreamContendConverter(String[] args)
{
m_inputFilePath = args[0];
m_inputCodePage = args[1];
m_outputFilePath = args[2];
m_outputCodePage = args[3];
}
public void convertFile() throws Throwable
{
File iFile = new File(m_inputFilePath);
File oFile = new File(m_outputFilePath);
BufferedReader reader = null;
BufferedWriter writer = null;
try
{
if (m_inputCodePage.equalsIgnoreCase("default"))
{
reader = new BufferedReader(new InputStreamReader(new FileInputStream (iFile)));
}
else
{
reader = new BufferedReader(new InputStreamReader(new FileInputStream (iFile),m_inputCodePage));
}
if (m_inputCodePage.equalsIgnoreCase("default"))
{
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(oFile)));
}
else
{
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(oFile),m_outputCodePage));
}
System.out.println("inputFilePath="+m_inputFilePath);
System.out.println("inputCodePage="+m_inputCodePage);
System.out.println("outputFilePath="+m_outputFilePath);
System.out.println("outputCodePage="+m_outputCodePage);
String line;
while ((line = reader.readLine())!=null)
{
writer.write(line+"\n");
}
}
finally
{
reader.close();
writer.flush();
writer.close();
}
}
static public void main(String[] args)
{
if (args.length != 4)
{
System.out.println("benötige 4 Argumente: [inputfile][codepage] [outputfile] [codepage]");
System.exit(1);
}
StreamContendConverter stc = new StreamContendConverter(args);
try
{
stc.convertFile();
}
catch (Throwable t)
{
t.printStackTrace();
System.exit(-1);
}
System.out.println("ready");
}
}