I'm trying to write a string \n in a text file. But the result in the text file is a newline. I know that the \n represents a newline. But in my case, I really need to see the String \n, not the newline. How can I solve this?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
The \ character escapes the next character, as you say \n will create a newline. If you wish to output an actual \, you need to write:
That way the first slash escapes the second slash, generating an actual slash rather than escaping the n.
Use
"\\n"
. The first backslash escapes the second one and as a result one is printed to your output.You need to escape the
\
. This can be done by entering\\
.What you want is to print two characters, namely
\
andn
. According to your language's manual, to print\
you must escape it.n
is not among the characters you must escape. Therefore, you write\\
andn
, thus\\n
.Do you mean
instead of
you have to escape the backslash, so double it: