Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:54:22+00:00 2026-05-26T07:54:22+00:00

i want to have a xml file in the user specifed directory. for that

  • 0

i want to have a xml file in the user specifed directory. for that i hav already created a file expert .

      File file = new File("d:\Expert");

this is create the file export .xml at d:\ drive. but here i have mentioned the path in the program itself. but user couldn’t recognize this path. what i need to do is user should specify the path wherever he wants in his output console. for this i passed the variable in args[].in net beans i gave the arguments through properties of object ->run->arguments->d:…
later in the program i wrote like below code. and this is giving me the output.
but file is not creating at d:…it simply appends the strings. how do i create a file user specied directory???can anyone provide me the code snippet???

       public class    New {
    void Expor() throws IOException, TransformerConfigurationException  

    //adding a node after the last child node of the    specified node.

     Element child = doc.createElement("body");
   root.appendChild(child);
   System.out.println("file created successfully");

   //TransformerFactory instance is used to create Transformer objects.
   TransformerFactory factory = TransformerFactory.newInstance();
   Transformer transformer = factory.newTransformer();
   transformer.setOutputProperty(OutputKeys.INDENT, "yes");

  // create string from xml tree
   StringWriter sw = new StringWriter();
   StreamResult result = new StreamResult(sw);
    DOMSource source = new DOMSource(doc);
   transformer.transform(source, result);
   String xmlString = sw.toString();

  File file = new File("expert");// creates the file if i mentioned D:/Export.xml
    //System.out.println(file.getName());
 //  System.out.println(file.getAbsolutePath());
         String path=readpath+filename;
     System.out.println(path);
BufferedWriter bw = new BufferedWriter
  (new OutputStreamWriter(new FileOutputStream(file)));
      bw.write(xmlString);

   bw.flush();
      bw.close();
 }
      public static void main(String argv[]) throws SQLException, IOException,            
   {
   if (argv.length == 0) {

   System.out.println("No Command Line arguments");

       } else {
System.out.println("You provided " + argv.length
   + " arguments");

    for (int i = 0; i < argv.length; i++) {
     System.out.println("args[" + i + "]: "
      + argv[i]);

    }
   }
    New e= new   New ();
        e.connectDB();
           }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:54:23+00:00Added an answer on May 26, 2026 at 7:54 am

    Based on what you’ve provided so far (which is a bit of a mess, and hard to read), it looks like you want to make 2 changes:

    1: Change your main method to be something like:

    public static void main(String argv[]) throws Exception 
    {
        New e= new   New ();
        e.connectDB();
        if(argv.length == 0)
            e.xmlExport("D:\\export.xml");
        else 
            e.xmlExport(argv[0]);
    }
    

    2: Change your xmlExport method to be:

    void xmlExport(String fileName) throws IOException, TransformerConfigurationException
    {
         // ...
         File file = new File(fileName);
         // ...
     }
    

    If that’s not what you want, then you’ll need to explain your question more clearly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a xml file that looks like this: <DataTalk> <Posts> <TalkPost> <PostType>dialog</PostType> <User>ABBE</User>
I have this XML file that I have imported into Cocoa and want to
I have an xml file that I want to configure using a bash script.
I have an XML file (on the left) and I want to create multiple
I have a single XML file that I want to index using Lucene.NET. The
I have thread where downloading xml file a this xml file i want to
I have a XML file like that: <Users> <User> <Adress Name=bbbb/> <Adress Name=aaaa />
Updated to be clear. Step One: I have a XML file that I want
I want to create xml file. I have three text fields and one button
I have a XML file like this : <?xml version=1.0 encoding=UTF-8 standalone=no ?> <user>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.