小编Rek*_*249的帖子

用单反斜杠替换双反斜杠

我有一个路径(例如C:\ Users \ chloe \ Documents),但是当我要将其保存在属性文件中时,由于字符串“ C:\ Users \ chloe \ Documents”,它会以双斜杠保存它由于某些原因,它没有放在\\C:之后。我在互联网上搜索,他们正在谈论replaceAll:

path.replaceAll("/+", "/");
Run Code Online (Sandbox Code Playgroud)

但这代替了常规的斜杠,我想知道如何用反斜杠...(在java中)

这是我写入属性文件的方式(仅需要的内容):

Properties prop = new Properties();
OutputStream output = null;


try {
                output = new FileOutputStream("config.properties");
                prop.setProperty("dir", path);
                prop.store(output, null);
            }catch(IOException e1){
                e1.printStackTrace();
            } finally {
                if (output != null) {
                    try {
                        output.close();
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }

            }

 path = System.getProperty("user.home") + File.separator + "AppData" + File.separator + "Roaming";
Run Code Online (Sandbox Code Playgroud)

java file path

-1
推荐指数
1
解决办法
1631
查看次数

标签 统计

file ×1

java ×1

path ×1