简体   繁体   English

为什么我在扫描仪上使用路径?

[英]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: StringPath重载做不同的事情:

  • The String is the data the Scanner will tokenize. StringScanner将标记化的数据。 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'malittleteapot
  • The Path is where to find the data for to be tokenized. Path查找要标记化的数据的位置。 For example, it points to a file containing the data.例如,它指向一个包含数据的文件。 The tokens it returns will depend upon the contents of the file identified by that path.它返回的标记将取决于由该路径标识的文件的内容。

Which one you use depends on your use case.您使用哪一种取决于您的用例。

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

相关问题 为什么我可以在实现路径接口的实例上使用 java.util.Scanner - why can i use java.util.Scanner on an instance that implemented the path interface 如何使用具有完整文件路径的java Scanner类? - How do I use java Scanner class with complete file path? 为什么我要创建一个新的扫描仪? 在创建驱动程序时 - Why do I have to create a new Scanner? when creating a driver 为什么 Java 扫描仪会抛出 NoSuchElementException,除非我通过路径而不是文件声明我的扫描仪? - Why does Java Scanner throw a NoSuchElementException unless I declare my Scanner by Path instead of File? 何时以及为何使用Scanner? - When and why to use Scanner? 使用扫描仪时,为什么我的JOptionPane没有出现? - Why is my JOptionPane not appearing when I use a Scanner? nextLine忽略输入,但next()不这样做-为什么我要清除扫描仪? - nextLine ignoring input, but next() don't - why have i clear scanner? 为什么我必须输入两次整数才能使我的 Scanner 输入起作用? - Why do I have to put an integer twice for my Scanner input to work? 我是否必须更改我的代码才能使用扫描仪才能使 inputmismatch 异常起作用? - Do I have to change my code to use a scanner in order for inputmismatch exception to work? 为什么Scanner使用Scanner#ioException()而不抛出异常? - Why does Scanner use Scanner#ioException() instead of throwing the exception?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM