Vaild directory characters in Java?

Posted on 2006-05-25
Last Modified: 2010-04-17
I'm using the File object to query fileObj.isDirectory(mydir) and it's failing on a valid directory.  The directory in question is C:\files\c\temp\Downloads (0004)

Are spaces not allowed in java referenced directories?  Is it the paranthesis?  Are both bad?   Is there a way around this problem?  I'm referencing someone elses code that I don't have rights to recompile and he does a check with isDirectory.  I can't avoid that.  Is there any thing at all I can do?  Is there a list of valid dir characters so that I won't run into this problem again, if I merely need to avoid using some paths?  

I tested c:\files\c\temp\Downloads (I created this just to test) and that worked fine.  Any ideas?
Question by:nolij
    LVL 16

    Accepted Solution

    It is working fine on me like this

    File dir = new File("C:\\Downloads (0004)");

    LVL 24

    Expert Comment

    as suprapto45 shows it's a question of escaping the \ properly.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now