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 9050477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:39:30+00:00 2026-06-16T12:39:30+00:00

This is my code. File file = new File(src/qrcodescanner/xmlpac/+filename); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder

  • 0

This is my code.

File file = new File("src/qrcodescanner/xmlpac/"+filename);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder(); 
document = db.parse(file);
document.getDocumentElement().normalize();
  • 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-06-16T12:39:32+00:00Added an answer on June 16, 2026 at 12:39 pm

    If it can’t be red it most probably isn’t where you expect it to be. Judging by the code you posted I suppose that your xml file is intended to reside inside your jar/package structure.

    This is my test project structure:

    src
     |-- main
         |-- java
             |-- mypackage
                     MyCode.java
                     MyResource.xml
    

    The corresponding generated jar file is located at target/ directory and looks like this:

     mypackage
         MyCode.class
         MyResource.xml
    

    MyResource.xml looks like this:

    <a>b</a>
    

    MyCode.java looks like this:

    public class MyCode {
    
    public static void main(String[] args) throws Exception {        
        String packagePath= "/mypackage/MyResource.xml";
        String myPath ="src/main/java"+packagePath;
        File f = new File(myPath);
        System.out.println(f.exists());        
        InputStream is = Class.class.getResourceAsStream(packagePath);                
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder(); 
        Document d = db.parse(is);
        System.out.println(d.getElementsByTagName("a").item(0).getTextContent());         
        }    
    }
    

    When run it prints:

    true
    b
    

    Method getResourceAsStream is used for loading resources from inside the JAR. Hope that helps.

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

Sidebar

Related Questions

This is my code: File TempFiles = new File(Tempfilepath); if (TempFiles.exists()) { String[] child
This code: const string LabelToFind = goTo considered Harmful; using (var file = new
this code is correct?? String note = text.txt; FileWriter file = new FileWriter(note); Scanner
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
I'm using this coffeescript code: in a spec file: index = new MeetingIndex(render: false,
I have this problem: I want to generate a new source code file from
I have this code that saves a pdf file. FileStream fs = new FileStream(SaveLocation,
I created an Image with this code OpenFileDialog dlg = new OpenFileDialog(); dlg.FileName =
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I'm learning about pointers. Given this code: FILE* from = fopen("in.txt", "r"); FILE* to

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.