Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2006, 12:37 AM
Authorized User
 
Join Date: Apr 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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();
    }
}



 
Old May 4th, 2006, 01:01 AM
Authorized User
 
Join Date: Apr 2006
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to vakorde
Default

write a code to create another file your expected filenma and copy all the contents of the output.xml file.

---------------------------
Vikrant Korde
3i Infotech, Vashi,
Mumbai, Maharashtra, India.
 
Old May 18th, 2006, 12:17 PM
Authorized User
 
Join Date: Apr 2005
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try

http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#renameTo(java.io.File)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming File ayazhoda Access VBA 3 April 24th, 2007 05:43 AM
Renaming App_Code jacob .NET Web Services 5 July 4th, 2006 12:20 AM
Renaming a table ... ERROR ?! SKE Classic ASP Databases 2 May 16th, 2005 06:04 AM
Renaming a dB ioates SQL Server 2000 3 July 2nd, 2003 02:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.