java非法类型_Java非法的类型开始try

importjava.io.*;importjava.util.Scanner;importjava.util.ArrayList;publicclassData{privateArrayListemployees;privatefinalStringEMPLOYEE_FILE="employees.txt";public...

import java.io.*;

import java.util.Scanner;

import java.util.ArrayList;

public class Data

{

private ArrayList employees;

private final String EMPLOYEE_FILE = "employees.txt";

public Data()

{

employess = new ArrayList();

}

public void readFile()

{

String filename = "employees.txt";

FileReader fr = new FileReader(filename);

Scanner parser = new Scanner (fr);

String name = parser.nextLine();

System.out.println(name);

fr.close();

}

String filename = ("employees.txt");

try //这里 非法的类型开始

{

FileReader fr = new FileReader(filename);

try

{

Scanner parser = new Scanner (fr);

int number = parser.nextInt();

}

finally

{

System.out.println(number);

fr.close();

}

}

catch(FileNotFoundException exception)

{

System.out.println(filename + " not found");

}

catch(IOException exception)

{

System.out.println("Unexpected I/O error occured");

}

}

想让这个类读取一个文本文件 然后将读取的内容存到collection里 最后显示在屏幕上

请指教 先谢过了

import java.io.*;

import java.util.Scanner;

import java.util.ArrayList;

public class Test

{

private ArrayList employees;

private final String EMPLOYEE_FILE = "employees.txt";

public Test()

{

employees = new ArrayList();

}

public void readFile()

{

try

{

String filename = "employees.txt";

FileReader fr = new FileReader(filename);

Scanner parser = new Scanner (fr);

String name = parser.nextLine();

System.out.println(name);

fr.close();

}

catch (Exception e)

{

e.printStackTrace();

}

}

}

感谢surplushaode的答案 这个可以运行了

展开

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值