用于文件名的字符串具有转义字符“\”。如何解决这个问题? [英] String used for a file name has escape character "\". How do I get around this?
本文介绍了用于文件名的字符串具有转义字符“\”。如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PrintWriter out =
new PrintWriter("C:\Users\Slerig\Desktop\gnuplot\binary\cannonballOutput.txt");
这是我的示例代码。这很简单。它抛出一个无效的转义字符错误,因为反斜杠。如何解决这个问题?编程Java btw。
This is my sample code. It is quite simple. It throws a "Invalid Escape Character" error because of the backslashes. How do I get around this? Programming in Java btw.
推荐答案
您必须转义 \
使用 \\
(或改用 /
)
使用
You'll have to escape \
with \\
in your string (or use /
instead)
Use
PrintWriter out =
new PrintWriter("C:\\Users\\Slerig\\Desktop\\gnuplot\\binary\\cannonballOutput.txt");
这篇关于用于文件名的字符串具有转义字符“\”。如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文