java - String literal is not properly closed 错误的反斜杠

标签 java

这是我的部分代码

OutputStream os;
    if (isWin){
        os = new FileOutputStream(folder + "\" + destinationFile);
    }
    else{
        os = new FileOutputStream(folder + "/" + destinationFile);
    }

我在反斜杠行收到“字符串文字未被双引号错误正确关闭”。如果我删除反斜杠或将其更改为正斜杠,错误将消失。

我该如何解决这个问题?谢谢。

最佳答案

分隔符最好使用 File api,这样你就不必检查它是什么操作系统了:

os = new FileOutputStream(folder + File.separatorChar + destinationFile);

关于java - String literal is not properly closed 错误的反斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31852318/

相关文章:

java - JNDI 缓存中存储了什么?

java - install4j updater 是否支持多交付 channel (稳定版/测试版/每晚)?

java - 合成器外观中的默认按钮输入映射?

java - 用Gson写入引用值

java - 访问当前用户,在 spring Controller 中,getAuthentication() 返回 null

java - 为什么我的 struts 注释重定向不起作用?

java - 人们是否提供多种机制来在 API 中做同样的事情?

java - 使我的 Java 程序易于分发

java - 摆弄 Java Graphics,这工作_一次_

java - 使用 hibernate 连接数据库时出错