Home java Syntax error in file name, folder name or volume label

Syntax error in file name, folder name or volume label

Author

Date

Category

Guys, please tell me how to specify the path to the file so that it does not swear?
FileNotFoundException

public boolean changeValuesInFiles () {
      for (File f: newFilesList) {
        try {
          String filepath = "file: ///" + f.getAbsolutePath ();
          DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance ();
          DocumentBuilder docBuilder = docFactory.newDocumentBuilder ();
          Document doc = docBuilder.parse (filepath);
          Node pointOfSale = doc.getElementsByTagName ("PointOfSale"). Item (0);
          NamedNodeMap attr = pointOfSale.getAttributes ();
          Node nodeAttr = attr.getNamedItem ("PointOfSaleCode");
          nodeAttr.setTextContent ("999");
          nodeAttr = attr.getNamedItem ("ParentPointOfSale");
          nodeAttr.setTextContent ("999");
          pointOfSale = doc.getElementsByTagName ("PointOfSaleDescription"). item (0);
          attr = pointOfSale.getAttributes ();
          nodeAttr = attr.getNamedItem ("Description");
          nodeAttr.setTextContent ("999");
          TransformerFactory transformerFactory = TransformerFactory.newInstance ();
          Transformer transformer = transformerFactory.newTransformer ();
          DOMSource source = new DOMSource (doc);
          StreamResult result = new StreamResult (new File (filepath));
          transformer.transform (source, result);
          return true;
        } catch (ParserConfigurationException e) {
          e.printStackTrace ();
        } catch (IOException e) {
          e.printStackTrace ();
        } catch (SAXException e) {
          e.printStackTrace ();
        } catch (TransformerConfigurationException e) {
          e.printStackTrace ();
        } catch (TransformerException e) {
          e.printStackTrace ();
        }
      }
      return false;
    }

Answer 1, authority 100%

Instead of passing the file path

Document doc = docBuilder.parse (filepath);

Pass the file object itself

Document doc = docBuilder.parse (f);

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions