简体   繁体   English

Shell脚本Java程序无法正确写入文件

[英]Shell script java program not writing files correctly

I have a java program that syncs the content of two directories. 我有一个Java程序,用于同步两个目录的内容。 The program takes the two directories as arguments. 该程序将两个目录作为参数。

I created a shell script to run the program on Linux. 我创建了一个Shell脚本以在Linux上运行该程序。 When the program firsts runs it creates a .sync file in each directory, this work perfectly on windows but is causing me some issues on linux. 程序.sync运行时,它将在每个目录中创建一个.sync文件,该文件在Windows上可以正常运行,但在Linux上却引起了我一些问题。 I'm very new to linux so unsure what is really going on. 我对Linux非常陌生,所以不确定到底发生了什么。

My program uses the following piece of code to create the .sync file... 我的程序使用以下代码段创建.sync文件...

FileWriter fileDir1 = new FileWriter(dir1 + "\\.sync");
fileDir1.write(obj.toJSONString());
fileDir1.flush();
fileDir1.close();

When I run the program on linux the files are being created in the same directory as the two directories are located instead of inside the two directories. 当我在Linux上运行程序时,文件将在两个目录所在的目录中创建,而不是在两个目录中创建。 The resulting files look like this.. 生成的文件如下所示。

dir1\\.sync and dir2\\.sync dir1\\.syncdir2\\.sync

Any help would be great. 任何帮助都会很棒。

使用正斜杠/代替转义的反斜杠\\\\ ,它在Windows和Linux上都可以使用。

FileWriter fileDir1 = new FileWriter(dir1 + "/.sync");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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