android - java.net.MalformedURLException: Protocol not found: but file exists -


hi i've little method:

private void modifyxml() {         try {              string filepath = main.filewithpath;             file f = new file(filepath);             if(f.exists()){                 system.out.println("exists");             }                documentbuilderfactory docfactory = documentbuilderfactory                     .newinstance();             documentbuilder docbuilder = docfactory.newdocumentbuilder();             document doc = docbuilder.parse(filepath);             doc.getdocumentelement().normalize();             nodelist nlist = doc.getelementsbytagname("daqchannel");  //          int sorszam = table.row_id-1; // //          node nnode = nlist.item(sorszam); //           //          if (nnode.getnodetype() == node.element_node) { //              element eelement = (element) nnode; //               //              eelement.getelementsbytagname("name").item(0).settextcontent(namee.gettext().tostring());    //              eelement.getelementsbytagname("unit").item(0).settextcontent(namee.gettext().tostring()); //              eelement.getelementsbytagname("minimum").item(0).settextcontent(namee.gettext().tostring()); //              eelement.getelementsbytagname("maximum").item(0).settextcontent(namee.gettext().tostring()); //              eelement.getelementsbytagname("accuracy").item(0).settextcontent(namee.gettext().tostring()); //              eelement.getelementsbytagname("sensortype").item(0).settextcontent(namee.gettext().tostring()); //              eelement.getelementsbytagname("registeraddress").item(0).settextcontent(namee.gettext().tostring()); //              eelement.getelementsbytagname("offset").item(0).settextcontent(namee.gettext().tostring()); //              eelement.getelementsbytagname("timestamp").item(0).settextcontent(namee.gettext().tostring()); //          }              // write content xml file             transformerfactory transformerfactory = transformerfactory.newinstance();             transformer transformer = transformerfactory.newtransformer();             domsource source = new domsource(doc);              string mydate = java.text.dateformat.getdatetimeinstance().format(calendar.getinstance().gettime());              string ujpath = filepath.substring(0, filepath.length()-10);               streamresult result = new streamresult(new file(ujpath+"/config_midified_"+mydate+".xml"));             transformer.transform(source, result);              system.out.println("done");           } catch (parserconfigurationexception pce) {             pce.printstacktrace();         } catch (transformerexception tfe) {             tfe.printstacktrace();         } catch (ioexception ioe) {             ioe.printstacktrace();         } catch (saxexception sae) {             sae.printstacktrace();         }      } 

it prints out file exists right in begining, got error message java.net.malformedurlexception: protocol not found:

please me did wrong!

thank you!

pass file instance instead

document doc = docbuilder.parse(new file(filepath)); 

when passing string, documentbuilder#parse() needs in uri format

[scheme:][//authority][path][?query][#fragment] 

i.e. along protocol file://.

reference :
documentbuilder#parse(string)


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -