[英]Why I have use Path on Scanner?
Why I can just use the String adress, like "C:/Users/CleBo/IdeaProjects/test/status.txt"
.为什么我只能使用字符串地址,例如
"C:/Users/CleBo/IdeaProjects/test/status.txt"
。 Why I have show it in Path, like:为什么我在 Path 中显示它,例如:
Path path = Paths.get ("C:/Users/CleBo/IdeaProjects/test/status.txt").
If I write System.out.println ("C:/Users/CleBo/IdeaProjects/test/status.txt")
it will be the same thing if I write:如果我写
System.out.println ("C:/Users/CleBo/IdeaProjects/test/status.txt")
如果我写的话,它会是一样的:
System.out.println(path);
What the different?有什么不同?
The String
and Path
overloads do different things: String
和Path
重载做不同的事情:
String
is the data the Scanner
will tokenize. String
是Scanner
将标记化的数据。 For example, if you call new Scanner("I'm a little teapot")
, that scanner will return the tokens I'm
, a
, little
and teapot
.new Scanner("I'm a little teapot")
,该扫描仪将返回令牌I'm
、 a
、 little
和teapot
。Path
is where to find the data for to be tokenized. Path
是查找要标记化的数据的位置。 For example, it points to a file containing the data. Which one you use depends on your use case.您使用哪一种取决于您的用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.