问题描述
大家好,
我知道"\"是转义字符,但是真的不可能将它读作正常"字符吗?
我想逐个字符地读取路径(以字符串形式读出),并检查一个路径是否为反斜线..但这仅在我在路径中加上双反斜线时才有效.
希望您能对我有所帮助!
Hi guys,
I know that "\" is an escape character, but is there really no possibility to read it as a "normal" character?
I wanted to read a path (which is read out in a string) character by character and check whether one is a backslash.. but that only works if i put double backslashes in the path.
Hope you can help me!
推荐答案
String slash = "\\";
别无选择.
There''s no alternatives.
import java.util.Properties;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java io.IOException;
并用
加载文件
and loaded the file with
private static String InFile;
String Path;
Properties props = new Properties();
FileInputStream in = null;
// create input stream to read file
try{
in = new FileInputStream(new File(Path));
} catch(FileNotFoundException e1) {
ErrorHandling.printError("Error");
}
try{
props.load(in);
} catch(IOException e) {
ErrorHandling.printError("Error");
}
我通过用关键词p.E.在文件中搜索来找到自己的路径.
I got my path by searching in file by a key word p.E.
InFile = props.getProperty("Path=");
那不是我所做的好主意.
如我所说,我想检查路径中是否有反斜杠,如果是,则添加另一个反斜杠.
好吧,这就是我所做的,而不是使用此属性:
and thats not a good idea for that what I did.
As I said, I wanted to check if there is any backslash in the path, if yes then add another backslash.
Well, that''s what I did instead of using this properies:
import java.util.Scanner;
import java.io.FileReader;
String Lines = null;
FileReader fr = new FileReader(Path);
Scanner input = new Scanner(fr);
// read out each line of file
while(input.hasNextLine())
{
Lines = input.nextLine();
System.out.println(Lines);
}
我希望每个人都能理解我要解释的内容:)
Painjofshem
I hope everyone understand what I''m trying to explain :)
Painjofshem
这篇关于我需要有关Java中双反斜杠和单反斜杠的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!