【问题标题】:scala io throws error while reading a filescala io在读取文件时抛出错误
【发布时间】:2022-01-23 01:59:30
【问题描述】:

当我尝试使用 scala 读取文件时,它不起作用,但在这个位置我有文件

这是权限问题

scala> val loc =  "C:\\Users\\gvenk\\OneDrive\\Desktop\\Input\\accountdetails.txt"
 loc: String = C:\Users\gvenk\OneDrive\Desktop\Input\accountdetails.txt

 scala> Source.fromFile(loc, "UTF-8").getLines().toList
 java.io.FileNotFoundException: C:\Users\gvenk\OneDrive\Desktop\Input\accountdetails.txt (The 
 system cannot find the file specified)
 at java.io.FileInputStream.open0(Native Method)
 at java.io.FileInputStream.open(FileInputStream.java:195)
 at java.io.FileInputStream.<init>(FileInputStr

【问题讨论】:

  • 它是否以某种方式Source.fromFile-特定? (new java.io.File(loc)).exists() 也说存在吗?

标签: scala


【解决方案1】:

解决方案在错误消息中:The system cannot find the file specified。这意味着文件不存在或拼写错误。

【讨论】:

    猜你喜欢
    • 2014-02-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2016-08-18
    • 2018-12-29
    • 2015-09-09
    • 2023-03-26
    相关资源
    最近更新 更多