简体   繁体   中英

java string escaping issue

I have the following code:

if (file.getParent().equals("Care Compass\\js")) {
    System.out.println(Files.getNameWithoutExtension("$$$"+entry.getName()));
}

The sysout for

file.getParent()

is the string:

Care Compass\js

But the above If condition won;t hold true. What am i missing here?

Thanks!

Posting some more code as per the comments:

try {
    ZipFile zipFileTemp = new ZipFile(zipFile);
    Enumeration<? extends ZipEntry> enumeration = zipFileTemp.entries();
    while (enumeration.hasMoreElements()){
        ZipEntry entry = enumeration.nextElement();
        File file;
        if(Files.getFileExtension(entry.getName()).equals("js")){
            jsFileName = entry.getName();
            file = new File(entry.getName());
            System.out.println("****%"+file.getAbsolutePath());
            System.out.println("****%%"+file.getName());

            System.out.println("****"+entry.getName());
            System.out.println(entry.getName());

            System.out.println("p="+file.getParent());

            if (file.getParent().toString().equals("Care Compass\\js")) {
                System.out.println(Files.getNameWithoutExtension("$$$"+entry.getName()));
            }
        }
    }
}

and the output is this:

****%C:\Workspaces\CCQueryHotkey\sqlfindertoolMultiThreaded\Care     
Compass\js\carecompass-ui-1.3.0.6.min.js
****%%carecompass-ui-1.3.0.6.min.js
****Care Compass/js/carecompass-ui-1.3.0.6.min.js
Care Compass/js/carecompass-ui-1.3.0.6.min.js
p=Care Compass\js
carecompass-ui-1.3.0.6.min

Are you sure file.getParent( ) returns string? sysout would print the toString( ) value, so use file.getParent().toString().equals in your if condition

我知道问题出在哪里...抱歉.. Files.getNameWithoutExtension("$$$"+entry.getName())正在剥离$$$ ..这是Files.getNameWithoutExtension("$$$"+entry.getName()) ,只是字符串已被剥离由.getNameWithoutExtension()淘汰

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM