我的txt文件和FileInputStream错误

时间:2019-07-03 19:52:50

标签: java filenotfoundexception fileinputstream

我有以下代码,返回带有txt信息的链表。问题是出现以下错误:

“找不到文件。MSJ: java.io.FileNotFoundException:D:\ Desktop \ game.txt(文件名,目录名或卷标的语法不正确)。

我的文件路径正确,我的txt是UTF-8,语法如下:

  ID Game: 0
  ID Stadium: 1
  ID Team 1: 102
  ID Team 2: 110
  Date Game: 2011-12-03
  --------------------------------------------
  ID Game: 1
  ID Stadium: 1
  ID Team 1: 102
  ID Team 2: 110
  Date Game: 2011-12-03
  --------------------------------------------
  ID Game: 2
  ID Stadium: 1
  ID Team 1: 102
  ID Team 2: 110
  Date Game: 2011-12-03
  --------------------------------------------

我正在使用的代码是这样:

    public class ReadInfo_Carlos {

    private static LL_Games_Carlos llg;

    public static LL_Games_Carlos getGames(String filePath)
    {

    FileInputStream inputStream = null;

    Scanner sc = null;

    String sep="--------------------------------------------";

    try {


        inputStream = new FileInputStream(filePath);

        sc = new Scanner(inputStream, "UTF-8");

        String line = sc.nextLine();

        String[] s = null;

        String idG=null, idS=null, idTeam1=null, idTeam2=null, date=null;

        while(sc.hasNextLine()){

            while(!line.equals(sep)){

                s = line.split("ID Game: ");

                if(s.length>1) idG = s[1];

                line = sc.nextLine();


                s = line.split("ID Stadium: ");

                if(s.length>1) idS = s[1];

                line = sc.nextLine();


                s = line.split("ID Team 1: ");

                if(s.length>1) idTeam1 = s[1];

                line = sc.nextLine();


                s = line.split("ID Team 2: ");

                if(s.length>1) idTeam2 = s[1];

                line = sc.nextLine();


                s = line.split("Date Game: ");

                if(s.length>1) date = s[1];

                line = sc.nextLine();

            }

            if(sc.hasNextLine())

                line = sc.nextLine();

            llg.Insert(Integer.parseInt(idG), Integer.parseInt(idS), Integer.parseInt(idTeam1), Integer.parseInt(idTeam2), LocalDate.parse(date));

        }



    } catch (FileNotFoundException ex) {

        System.out.println("File not found. MSJ: \n"+ex);

    } finally {

        if (inputStream != null) {

            try {

                inputStream.close();

            } catch (IOException ex) {

                System.out.println("IO Exception. MSJ: \n"+ex);

            }

        }

        if (sc != null) {

            sc.close();
        }
    }
    return llg;
  }



 public static void main(String[] args) 
 {
    String filePath = "‪‪D:\\Desktop\\game.txt";
    ReadInfo_Carlos.getGames(filePath);
 }

0 个答案:

没有答案