zoukankan      html  css  js  c++  java
  • java.io.FileNotFoundException: XXX (系统找不到指定的路径。)

     1 import java.io.*;
     2 import java.util.Objects;
     3 
     4 public class CSVFile {
     5 
     6     public static void main(String[] args) {
     7         String filePath = Objects.requireNonNull(CSVFile.class.getClassLoader().getResource("data.txt")).getPath();
     8         printCSVFile(filePath);
     9     }
    10     
    11     public static void printCSVFile(String filePath) {
    12         //add code here
    13         System.out.println("Last    Fisrt    Salary");
    14         try {
    15             BufferedReader br = new BufferedReader(new FileReader(filePath));
    16             String temp;
    17             while((temp = br.readLine()) != null) {
    18                 String[] tempList = temp.split(",");
    19                 for(int i = 0; i < tempList.length; i++) {
    20                     if(i < tempList.length - 1) {
    21                         System.out.print(tempList[i] + "    ");
    22                     }
    23                     else {
    24                         System.out.println(tempList[i]);
    25                     }
    26                 }
    27             }
    28         } catch (IOException ex) {
    29             ex.printStackTrace();
    30         }
    31     }
    32 
    33 }

    以上代码检查后发现没有什么问题,但运行时报错

     1 Last    Fisrt    Salary
     2 java.io.FileNotFoundException: D:\%e4%bd%9c%e4%b8%9a\%e8%bd%af%e4%bb%b6%e5%b7%a5%e7%a8%8b%e4%b8%8e%e8%ae%a1%e7%ae%97ICodeSpace2e6400dff19b495493514ed0a5c2cd25236-testcsvfile	argetclassesdata.txt (系统找不到指定的路径。)
     3     at java.io.FileInputStream.open0(Native Method)
     4     at java.io.FileInputStream.open(FileInputStream.java:195)
     5     at java.io.FileInputStream.<init>(FileInputStream.java:138)
     6     at java.io.FileInputStream.<init>(FileInputStream.java:93)
     7     at java.io.FileReader.<init>(FileReader.java:58)
     8     at CSVFile.printCSVFile(CSVFile.java:15)
     9     at CSVFile.main(CSVFile.java:8)
    10 
    11 Process finished with exit code 0

    百思不得其解,最终发现是因为文件路径包含中文(lll¬ω¬)

    重构系统文件目录,改用英文刻不容缓!!!ㄟ( ▔, ▔ )ㄏ

  • 相关阅读:
    Docker部署LAMP搭建wordpress博客系统
    Docker教程---基本操作
    华为VS网络虚拟化技术
    云数据中心基础设施层概述
    EVE-NG模拟器关联SecureCRT、Wireshark软件
    Centos7.4安装openstack(queens)cinder卷类型和云主机安全
    围观大神的文件读取操作
    浅谈python垃圾回收机制
    Python网络爬虫开发实战使用XPath,xpath的多种用法
    快来学习怎么可视化监控你的Python爬虫
  • 原文地址:https://www.cnblogs.com/Neptunejiang/p/12656321.html
Copyright © 2011-2022 走看看