JAVA读取TXT文件然后再把读取出来的数据封装到数组里,JAVA代码怎么实现,求大神告知
展开全部
String textFile="c://test.txt";
File file = new File(textFile);
FileInputStream fis=null;
List<String> list = new ArrayList<String>();
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
InputStreamReader isr = null;
try {
isr = new InputStreamReader(fis,"GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
};
BufferedReader reader = new BufferedReader(isr);
String str = null;
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
reader = new BufferedReader(isr);
try {
//按行读取
while ((str = reader.readLine()) != null) {
list.add(str);
}
} catch (IOException e) {
e.printStackTrace();
}
File file = new File(textFile);
FileInputStream fis=null;
List<String> list = new ArrayList<String>();
try {
fis = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
InputStreamReader isr = null;
try {
isr = new InputStreamReader(fis,"GBK");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
};
BufferedReader reader = new BufferedReader(isr);
String str = null;
try {
str = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
reader = new BufferedReader(isr);
try {
//按行读取
while ((str = reader.readLine()) != null) {
list.add(str);
}
} catch (IOException e) {
e.printStackTrace();
}
追问
List list = new ArrayList();这个地方报错啊
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询