Insert numbers starting with one in each xml files sequentially

The following is a sample of two of my xml files
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article SYSTEM "abc.dtd">
<article xyz>
<front>
<product>
<citation citation-type="book" id="">
</citation>
</product>
<product>
<citation citation-type="book" id="">
</citation>
</product>
</front>
</article>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article SYSTEM "abc.dtd">
<article xyz>
<front>
<product>
<citation citation-type="book" id="">
</citation>
</product>
<product>
<citation citation-type="book" id="">
</citation>
</product>
<product>
<citation citation-type="book" id="">
</citation>
</product>
<product>
<citation citation-type="book" id="">
</citation>
</product>
</front>
</article>
This is my source code
public class ReadTexFile
     public void Go2Directory(String Directory)
                File scan = new File(Directory);
          String DirList[] = scan.list();
          try
               for(int i = 0; i < DirList.length; i++)
                    File ChkDir = new File((new StringBuilder()).append(scan.getPath()).append("\\").append(DirList).toString());
                    if(ChkDir.isFile())
                         dum1 = ChkDir.toString().toUpperCase();
                         if(dum1.lastIndexOf(".XML") > 0)
String ExecFile = ChkDir.toString();
                              File TexfileName = new File(ExecFile);
                              ReadFileContent(TexfileName);
                              fileCount++;
                         if(!ChkDir.exists())
                              System.out.println((new StringBuilder()).append("NO FILES FOUND IN THE DIRECTORY").append(scan).toString());
          catch(Exception e)
               System.out.println((new StringBuilder()).append("The Error Is in ").append(e).toString());
     public void ReadFileContent(File TexFile)
try
               BufferedReader br = new BufferedReader(new FileReader(TexFile));
               String fetchline = "";
               for(String line = ""; (line = br.readLine()) != null;)
                    fetchline = (new StringBuilder()).append(fetchline).append(line).append("00000000").toString();
               br.close();
cntr=1;
               fetchline = RemoveIfAlreadyExist(fetchline);
               fetchline = fetchline.replace("00000000", "\n");
               File tmp = new File(TexFile.getParent(), "XmlFileTmp.xml");
               BufferedWriter bw = new BufferedWriter(new FileWriter(tmp));
               bw.write(fetchline);
               bw.flush();
               bw.close();
               File org = new File(TexFile.getAbsolutePath());
               System.gc();
               tmp.renameTo(org);
          catch(IOException ioe)
               System.out.println((new StringBuilder()).append("The IO Exception occured because ").append(ioe.getMessage()).toString());
          catch(NullPointerException npe)
               System.out.println((new StringBuilder()).append("The Null Pointer Exception occured because ").append(npe.getMessage()).toString());
     public String RemoveIfAlreadyExist(String line)
String res = "";
int cc=1;
          Pattern Regex = Pattern.compile("<product>00000000<citation citation-type=\".*?\" id=\"\">");
          for(Matcher RegexMatcher = Regex.matcher(line); RegexMatcher.find();)
               String chkEntity = RegexMatcher.group();
               String subchkEntity1=chkEntity.substring(0,chkEntity.lastIndexOf("\">"));
               String s1 = Integer.toString(cc);
               if(s1.length()==1)
                    res = line.replace(subchkEntity1,subchkEntity1+"ref00"+cc+"");
               if(s1.length()==2)
                    res = line.replace(subchkEntity1,subchkEntity1+"ref0"+cc+"");
               if(s1.length()==3)
                    res = line.replace(subchkEntity1,subchkEntity1+"ref"+cc+"");
cc++;
          return res;
My output from my code is
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article SYSTEM "abc.dtd">
<article xyz>
<front>
<product>
<citation citation-type="book" id="ref002">
</citation>
</product>
<product>
<citation citation-type="book" id="ref002">
</citation>
</product>
</front>
</article>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article SYSTEM "abc.dtd">
<article xyz>
<front>
<product>
<citation citation-type="book" id="ref004">
</citation>
</product>
<product>
<citation citation-type="book" id="ref004">
</citation>
</product>
<product>
<citation citation-type="book" id="ref004">
</citation>
</product>
<product>
<citation citation-type="book" id="ref004">
</citation>
</product>
</front>
</article>
But I need my output as
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article SYSTEM "abc.dtd">
<article xyz>
<front>
<product>
<citation citation-type="book" id="ref001">
</citation>
</product>
<product>
<citation citation-type="book" id="ref002">
</citation>
</product>
</front>
</article>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article SYSTEM "abc.dtd">
<article xyz>
<front>
<product>
<citation citation-type="book" id="ref001">
</citation>
</product>
<product>
<citation citation-type="book" id="ref002">
</citation>
</product>
<product>
<citation citation-type="book" id="ref003">
</citation>
</product>
<product>
<citation citation-type="book" id="ref004">
</citation>
</product>
</front>
</article>Could anyone please tell me what modifications to do in my code.

Hi sony,
Since you are trying to replace the pattern of subchkEntity1,
it replaces all the lines which contain ("<citation citation-type="book" id=")
including(...id="refxxx...)
& not ("<citation citation-type="book" id="") alone.
So ,to eliminate this, we have to match the string with chkEntity &
replace only the first occurance.
I've modified the method RemoveIfAlreadyExist.
It works fine now.
public String RemoveIfAlreadyExist(String line)
         int cc=1;
          Pattern Regex = Pattern.compile("<product>00000000<citation citation-type=\".*?\" id=\"\">");
          for(Matcher RegexMatcher = Regex.matcher(line); RegexMatcher.find();)
               String chkEntity = RegexMatcher.group();
               int lastIndex = chkEntity.lastIndexOf("\">");
               String subchkEntity1=chkEntity.substring(0,lastIndex);
               String s1 = Integer.toString(cc);
               if(s1.length()==1)
                    line = line.replaceFirst(chkEntity,subchkEntity1+"ref00"+cc+"\"");
               if(s1.length()==2)
                    line = line.replaceFirst(chkEntity,subchkEntity1+"ref00"+cc+"\"");
               if(s1.length()==3)
                    line = line.replaceFirst(chkEntity,subchkEntity1+"ref00"+cc+"\"");
                        cc++;
          return line;
     }

Similar Messages

  • I started with one itunes account for my iphone and ipad, and now have a second ipad linked to the same itunes.  Can I set up a new itunes account for one ipad without losing what has already been downloaded on it?

    I started with one itunes account for my iphone and ipad, and now have a second ipad linked to the same itunes.  Can I set up a new itunes account for one ipad without losing what has already been downloaded on it?  I want to stop my husbands downloads appearing on my ipad, and vice versa.

    A much simpler solution would be to go into Settings > Store and turn off Automatic Downloads

  • I have very thin, colored lines running vertical on my desktop monitor screen.  I don't know where they come from or how to get rid of them.  I started with one and now have three.  Can anyone give me some insight about what to do in getting rid of them?

    I have very thin, colored lines that have shown up on my IMac monitor screen.  I don't know where they came from or how to get rid of them.  I'm concerned now because I started with one and now have three.  Does any know why this occurs or how to get rid of them?

    I got an address from Applecare, although I can't place my hand on it right now. I didn't bother persuing the letter route myself as I didn't expect much. I know that the location was Cork, Ireland though as that where the UK Applecare is based as far as I'm aware. The best thing to do is to call Applecare (if it's free) and discuss the issue. State that you are not happy wit the fact that you will have to pay to have the problem resolved especiiay if it is an ongoing problem that has not been resolved. I ended up speaking to a senior manager of the Applecare team who then proceeded to tell me about mailing in my grievence to customer services division or something like that.
    If I can find the address I may post it if I'm allowed.
    In the case of age, Schools usually have a 5-year life-cycle as they tend to be used differently than consumer machines, i.e. being used constantly on a daily basis for at least 12 hours with no break. you would expect issues to appear after a few years, but I expect problems that arise through defects to be resolved and stay resolved. As I mentioned we had machines for around 2 years before the lines appeared and sent them to be repaired. I'm happy with that. What I am unhappy about is the fact that the problem has reappeared exactly in the same way and now I'm left with around 7 machines that I either pay loads to repair or, the more likely replace the machines with newer ones since the age is now big enough to warrant the replacement.
    Sorry for the lengthy moan, but these are the reasons I purchased Apple ahrdware in the first place to avoid the "not our problem" stance some PC vendors  usually take, similar to the Dell monitors thread mentioned in here somewhere.

  • I'm trying to input phone numbers starting with 0, into Numbers spreadsheet. It keeps deleting the 0-  any clues?

    I'm trying to input phone numbers starting with 0 into Numbers Spreadsheets. It keeps deleting the 0. any clues anyone?

    select the cells (or column) where you are entering the phone numbers and change the format to "Text":
    Then "Natural" way to write numbers is to omit leading zeros.
    Another ways is to leave the the cell format as "Automatic" and type a single quote BEFORE entering the phone number... like this:
    '0408

  • Make firefox start with one tab using mozilla.cfg

    i create new package for fire fox when start firefox it is open two tabs for same link
    i need it to start with one tab i use the this in my mozilla.cfg :
    <pre><nowiki>defaultPref("startup.homepage_welcome_url", "https://portal.field.weightwatchers.ca/");
    defaultPref("startup.homepage_override_url", "https://portal.field.weightwatchers.ca/");
    defaultPref("browser.startup.homepage", "data:text/plain,browser.startup.homepage=https://portal.field.weightwatchers.ca/");</nowiki></pre>

    When do you want to see this page?
    This only sets the default home page, so if users have change this setting then it won't have effect.<br />
    If you use pref() then you set this pref for the current session, but this will make it impossible to make changes that last across a session.
    You also may want to set to open the Home page on startup (browser.startup.page = 1).
    *CCK Wizard: https://addons.mozilla.org/firefox/addon/cck/

  • Three emails sent with one record each

    Hi all there are three records that result from the query but instead of sending all three results in the email it sends three emails with one record each. I can't use cfoutput in the cfmail tag. What do I do? Thanks 
    <cfquery name="qNames" datasource="salesdb">
    select * from company, industries, division
    where Date(company.meeting) = '#DateFormat(Now(),"yyyy-mm-dd")#'
    and company.SECTORS1 = industries.SECTORSIDS
    and division.DEPARTMENTIDS = company.DEPARTMENT1
    ORDER BY company</cfquery>
    <cfmail to="[email protected]"
    from=[email protected]
    subject="Today's email"
    type="text"
    query="qNames">
    Dear Fred
    #company#
    #sectorsnom#
    </cfmail>

    Hi
    Just add Cfoutput to output the value of the query in Cfmail tags Like shown below.
    <cfquery name="qNames" datasource="salesdb">
    select * from company, industries, division
    where Date(company.meeting) = '#DateFormat(Now(),"yyyy-mm-dd")#'
    and company.SECTORS1 = industries.SECTORSIDS
    and division.DEPARTMENTIDS = company.DEPARTMENT1
    ORDER BY company</cfquery>
    <cfmail to="[email protected]"
    from=[email protected]
    subject="Today's email"
    type="text"
    query="qNames">
    Dear Fred
    <cfoutput>
    #company#
    #sectorsnom#
    </cfoutput>
    </cfmail>
    You can also use cfloop before the cftag and get the data stored using <cfsavecontent >. Inside Cfmail you can output cfsavecontent value
    Please let me know if this post could help
    Regards
    Sreekar

  • Working with multiple faces-config.xml files

    I would organize the menu definitions of my application in different faces-config.xml files. I would also put the label in different properties files.
    The SRDemo application uses a unique properties file for the menu used in the el expression from the faces-config.xml.
    Is it possible to have the same approach with not only one faces-config.xml file but has many faces-config.xml i want for my application.
    If yes does the binding name to be different or may be the same for each file ?

    We still have a litlle problem we don't find the reason. May be you can help us.
    The second menu level never appear in the menu list. The menu list appear as empty.
    The menu bar seem to be correct. We put twice the same model tree to be sure it was working well. Both menu appears. It is correct.
    Here is our faces-config-menu-flexsystem.xml file
    <?xml version="1.0" encoding="windows-1252"?>
    <!DOCTYPE faces-config PUBLIC
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    <faces-config xmlns="http://java.sun.com/JSF/Configuration">
    <managed-bean>
    <description>Create menu item for flex system management</description>
    <managed-bean-name>menu_menuitem_FlexSystem_Create</managed-bean-name>
    <managed-bean-class>flex.view.util.MenuItem</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>label</property-name>
    <value>#{resources['menu.FlexSystem.menuItem.create']}</value>
    </managed-property>
    <managed-property>
    <property-name>viewId</property-name>
    <null-value/>
    </managed-property>
    <managed-property>
    <property-name>outcome</property-name>
    <value>linkToCreateNewFlexSystem</value>
    </managed-property>
    </managed-bean>
    <managed-bean>
    <description>Manage menu item for flex system management</description>
    <managed-bean-name>menu_menuitem_FlexSystem_Manage</managed-bean-name>
    <managed-bean-class>flex.view.util.MenuItem</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>label</property-name>
    <value>#{resources['menu.FlexSystem.menuItem.manage']}</value>
    </managed-property>
    <managed-property>
    <property-name>viewId</property-name>
    <value>\FlexHome.jspx</value>
    </managed-property>
    <managed-property>
    <property-name>outcome</property-name>
    <value>linkToManageFlexSystem</value>
    </managed-property>
    </managed-bean>
    <managed-bean>
    <description>Root menu item for flex system management</description>
    <managed-bean-name>menu_menuitem_FlexSystem_Root</managed-bean-name>
    <managed-bean-class>flex.view.util.MenuItem</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>children</property-name>
    <list-entries>
    <value-class>flex.view.util.MenuItem</value-class>
    <value>#{menu_menuitem_FlexSystem_Create}</value>
    <value>#{menu_menuitem_FlexSystem_Manage}</value>
    </list-entries>
    </managed-property>
    <managed-property>
    <property-name>label</property-name>
    <value>#{resources['menu.FlexSystem.menuItem.root']}</value>
    </managed-property>
    </managed-bean>
    <application>
    <message-bundle>flex.view.resources.MenuFlexSystemProperties</message-bundle>
    <locale-config>
    <supported-locale>fr_CH</supported-locale>
    </locale-config>
    </application>
    <managed-bean>
    <managed-bean-name>resources</managed-bean-name>
    <managed-bean-class>flex.view.util.ResourceAdapter</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
    <from-view-id>/FlexHome.jspx</from-view-id>
    <navigation-case>
    <from-outcome>linkToCreateNewFlexSystem</from-outcome>
    <to-view-id>/CreateNewFlexSystem.jspx</to-view-id>
    </navigation-case>
    </navigation-rule>
    <navigation-rule>
    <from-view-id>/FlexHome.jspx</from-view-id>
    <navigation-case>
    <from-outcome>linkToManageFlexSystem</from-outcome>
    <to-view-id>/ManageFlexSystem.jspx</to-view-id>
    </navigation-case>
    </navigation-rule>
    <managed-bean>
    <managed-bean-name>menu_FlexSystem</managed-bean-name>
    <managed-bean-class>flex.view.util.MenuTreeModelAdapter</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>childProperty</property-name>
    <value>children</value>
    </managed-property>
    <managed-property>
    <property-name>listInstance</property-name>
    <list-entries>
    <value-class>flex.view.util.MenuItem</value-class>
    <value>#{menu_menuitem_FlexSystem_Root}</value>
    <value>#{menu_menuitem_FlexSystem_Root}</value>
    </list-entries>
    </managed-property>
    </managed-bean>
    <managed-bean>
    <managed-bean-name>menuModel</managed-bean-name>
    <managed-bean-class>flex.view.util.MenuModelAdapter</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
    <property-name>viewIdProperty</property-name>
    <value>viewId</value>
    </managed-property>
    <managed-property>
    <property-name>instance</property-name>
    <value>#{menu_FlexSystem.model}</value>
    </managed-property>
    </managed-bean>
    </faces-config>

  • Can i make more than one faces-config.xml file ?

    Can i make more than one faces-config.xml file under one project or application, if yes than how it will link.

    Just that you know,
    In the second week of july I was taking the Jdeveloper/Jheadstart course at Oracle Netherlands. During that course we were asked to split the faces-config. After splitting it, we were not able to find the navigation rules that were defined in the first faces-config in the web.xml. The Jdeveloper IDE was confused........
    However, we were able to use the navigation rules (type in manualy) and that worked in the application.
    I talked about it with Steven Davelaar and he thought it might be a bug. I don't know if it's reported, and I don't know if it's fixed.
    So, if you get confused.... it works, but Jdeveloper might have some problems with it.
    Luc Bors

  • More than one struts-config.xml files in one project

    Hi all
    Can we have more than one struts-config.xml files in one project developed using struts.
    If so what is purpose and how to do this.
    Anybody please explain on this topic.
    Thanks
    Parvathy

    Hi all
    Can we have more than one struts-config.xml files in
    one project developed using struts.
    yes it is possible
    If so what is purpose and how to do this.
    it is use for odular application so developer won't share a single configureation file.. as you know struts-config.xml is defined on the web.xml
    like this:
    <servlet>
    <servlet-name>mybank</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet
    </servlet-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
    <param-name>config/module1</param-name>
    <param-value>
    /WEB-INF/struts-module1-config.xml
    </param-value>
    </init-param>
    </servlet>

  • Every time my Mac starts i see a Data.xml file in recycle bin

    every time my Mac starts i see a Data.xml file in recycle bin is that sort of malware ?

    Uninstall the program from the control panel or use a antimalware such as [http://www.malwarebytes.org/products/malwarebytes_free/ MalwareBytes' Anti-Malware].

  • How can I fill structure from the line with contetnt of a XML file inside?

    How can I fill structure from the line with contetnt of a XML file inside?
    I have array of lines with XML documents inside. All XML's have the same structure.
    I need to fill array of structures (with the same structure like given XML's) from data of these XML's.
    How can I do this? I am trying Transformation with ora:parseEscapedXML, but receive error: "XPath expression failed to execute.
    Error while processing xpath expression, the expression is "ora:processXSLT("Transformation_1.xsl", bpws:getVariableData("ProcessedFiles"))", the reason is javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: Could not find function: parseEscapedXML.
    Please verify the xpath query."

    Ive posted the new code but now I'm getting a FileAlreadyExistException error. How do I handle this exception error correctly in my code?
    import java.io.IOException;
    import java.nio.file.FileAlreadyExistsException;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println(templateElement.getAttribute("name")+ ".xml");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      String fileName = templateElement.getAttribute("name") + ".xml";
      Files.createFile(Paths.get(fileName));
      System.out.println("File" + ":" + fileName + ".xml created");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

  • One to many xml files with file adaptor

    Hi,
    I have a scenario HCM-ABAPProxy--XI-File for one structure I need to generate multiple xml files with 100 records per file.
    this is my input  messag
    MT_in
      Node
         PositionIDs
            descrption
            job
            IsActive
    what I was doing on the ABAP side for every node I have 100 PositionID's sub nodes. so each node should be a sperate file.
    my output structure is
    PositionIDs
        PositionID
          pid
          description
          job
    so there should be one PositionIDs per file which contains 100 PositionID.
    I've multi message mapping without BPM that did not work out just wondering if any one came across the same scenario.
    thanks,
    Joe

    You can not create multiple files without BPM. You can pretty much perform multi mapping to achieve your split but to write it to a file, you will have to call the file adapter for each split which you can not do without using BPM. In BPM, for each split that you perform, you can use a send step in for-each loop which will give you the functionality you require.
    Award if helpful,
    Sarath.

  • Use page numbers starting with 1 on the second page

    I have a document in Pages 09 that I need to have a title page. This page should have no page number so the numbers start on page 2. I have managed to get rid of the page number on the first page, but Pages keeps starting the numbers from 2 on the second page. I tried to set "Start at:" to 1, but that did have no effect. Is there any solution?

    From Vallauris I can't guess what but clearly, you forgot something !
    Compare your settings with these ones.
    Yvan KOENIG (VALLAURIS, France) vendredi 1 juillet 2011 14:00:35 iMac 21”5, i7, 2.8 GHz, 4 Gbytes, 1 Tbytes, mac OS X 10.6.8
    Please : Search for questions similar to your own before submitting them to the community
    To be the AW6 successor, iWork MUST integrate a TRUE DB, not a list organizer !

  • Insert multiple line with one call to a SQL procedure

    Hello,
    I'm working with BC4J and UIX/XML.
    Our purpose is to insert in a table more then one row at one time and put them (all the rows) in an array.
    Then, we have to save them at one time by calling one time the function doDML().
    Thanks.

    Hello,
    I'm working with BC4J and UIX/XML.
    Our purpose is to insert in a table more then one row at one time and put them (all the rows) in an array.
    Then, we have to save them at one time by calling one time the function doDML().You may use BatchUpdating feature in Bc4J to achieve this.
    The semantics for using this for an Entity is same as the normal - non-batch mode. However by adding a batch-threshold on the Entity defnition (Entity Object Editor/Tuning panel), you can control if that entity type has a given number of affected rows, then framework should use batchmode post operations).
    When this is turned on, one roundtrip from entity DML will contain all entities of that type for that operation,for example if you have inserts/deletes/updates for Dept, then in one roundtrip, all deletes will go followed by another roundtrip for inserts and another one for updates.

  • Wrong File(parent, child) behaviour on Windows when child starts with one s

    I've sent following problem report:
    A DESCRIPTION OF THE PROBLEM :
    On Windows when relative path starts from one slash it should be resolved from current disk (not current directory). This behaviour should be preserved for Files constructed with constructor File(parent, child). So results of run "System.out.println(new File(dir, relPath).getAbsolutePath())" and "System.out.println(new File(relPath).getAbsolutePath())" should be identical when running program from directory "dir".
    STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
    Compile and run from directory C:\temp\relpath following code:
    import java.io.*;
    public class Main {
         public static void main(String[] args) throws Exception {
              System.out.println(new File("C:\\temp\\relpath", "\\temp\\relpath\\Main.java").getAbsolutePath());
              System.out.println(new File("\\temp\\relpath\\Main.java").getAbsolutePath());
    EXPECTED VERSUS ACTUAL BEHAVIOR :
    EXPECTED -
    C:\temp\relpath>java Main
    C:\temp\relpath\\Main.java
    C:\temp\relpath\Main.java
    ACTUAL -
    C:\temp\relpath>java Main
    C:\temp\relpath\temp\relpath\Main.java
    C:\temp\relpath\Main.java
    The answer was:
    I have been analyzing your problem and it is not a bug but the intended behavior of the API.
    The File(File,String) constructor includes this in the specification:
    "If the |child| pathname string is absolute then it is converted into a relative pathname in a system-dependent way."
    In the example provided here, the child path is absolute so it is converted into a relative path. This is the intended behavior.
    My comments:
    First, child pathname is not absolute. Even so, I don't understand why this guy contend that this behavior is correct.
    Please comment this!

    Please comment this!
    I've sent following problem report:
    A DESCRIPTION OF THE PROBLEM :
    On Windows when relative path starts from one slash
    it should be resolved from current disk (not current
    directory). This behaviour should be preserved for
    Files constructed with constructor File(parent,
    child). So results of run "System.out.println(new
    File(dir, relPath).getAbsolutePath())" and
    "System.out.println(new
    File(relPath).getAbsolutePath())" should be identical
    when running program from directory "dir".
    STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
    Compile and run from directory C:\temp\relpath
    following code:
    import java.io.*;
    public class Main {
    public static void main(String[] args) throws
    s Exception {
    System.out.println(new File("C:\\temp\\relpath",
    ", "\\temp\\relpath\\Main.java").getAbsolutePath());
    System.out.println(new
    ew
    File("\\temp\\relpath\\Main.java").getAbsolutePath());
    EXPECTED VERSUS ACTUAL BEHAVIOR :
    EXPECTED -
    C:\temp\relpath>java Main
    C:\temp\relpath\\Main.java
    C:\temp\relpath\Main.java
    ACTUAL -
    C:\temp\relpath>java Main
    C:\temp\relpath\temp\relpath\Main.java
    C:\temp\relpath\Main.java
    The answer was:
    I have been analyzing your problem and it is not a
    bug but the intended behavior of the API.
    The File(File,String) constructor includes this in
    the specification:
    "If the |child| pathname string is absolute then it
    is converted into a relative pathname in a
    system-dependent way."
    In the example provided here, the child path is
    absolute so it is converted into a relative path.
    This is the intended behavior.
    My comments:
    First, child pathname is not absolute. Even so, I
    don't understand why this guy contend that this
    behavior is correct.
    */

Maybe you are looking for