【问题标题】:Shortest way to open file with encoding and readLine() in Java?在 Java 中使用编码和 readLine() 打开文件的最短方法?
【发布时间】:2012-01-05 07:39:36
【问题描述】:

使用 readLine() 方法打开文件进行读取并设置其编码的最短方法是什么?

以下行是否正确且最短?

BufferedReader reader = 
    new BufferedReader(
         new InputStreamReader(
             new FileInputStream(myPath), myEncoding));

【问题讨论】:

    标签: java file encoding readline


    【解决方案1】:

    使用Scanner,您可以这样做:Scanner scan = new Scanner(new File(myPath), myEncoding),然后是scan.nextLine(),它返回一个String

    【讨论】:

      猜你喜欢
      • 2010-09-18
      • 2011-06-05
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      • 2011-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多