Renaming filename
Could anyone please me with the below problem.
My input file for "argv[0]" is any sgm file
My output file is "ouput.xml"
For instance, if I pass my input file as "a003946.sgm", after all the necessary modifications, I need to rename my "ouput.xml" to "a003946.xml" without deleting my original input file.
Can anyone please me with the above problem.
My code is as below:
import java.io.*;
class browser
{
public static void main(String argv[]) throws IOException{
browser iop=new browser();
int val;
char ch;
FileReader fr = new FileReader(argv[0]);
FileWriter fw = new FileWriter("ouput.xml");
while((val = fr.read()) != -1){
ch = (char)val;
if(ch == '<'){
String str = "";
while((val = fr.read()) != -1){
ch = (char)val;
if(ch == '>')
break;
else
str = str + ch;
}
if(str.startsWith("!DOCTYPE") == true)
fw.write("!DOCTYPE article SYSTEM \"entity.dtd\">");
else if(str.startsWith("markref") == true)
fw.write("<" +str +"/>");
else
fw.write("<" +str +">");
}
else
fw.write(val);
}
fr.close();
fw.close();
}
}
|