给你我写的两个方法!!作为参考吧! /** * @author CaoShun * @see 从指定位置文件中一行一行读取内容并把每行存入List集合 * */ public static List readInputByRow(String path) { List list=new Array 展开
给你我写的两个方法!!作为参考吧! /** * @author CaoShun * @see 从指定位置文件中一行一行读取内容并把每行存入List集合 * */ public static List readInputByRow(String path) { List list=new ArrayList();File file=new File(path);try { FileInputStream fis = new FileInputStream(file);InputStreamReader isr = new InputStreamReader(fis, "UTF-8");BufferedReader reader = new BufferedReader(isr);String tempstring="";while((tempstring=reader.readLine())!=null) { list.add(tempstring);//System.out.println("debug in ReadWriteOEMInfo.java on line 99 tempstring : "+tempstring);} reader.close();isr.close();fis.close();return list;} catch (IOException e) { e.printStackTrace();return null;} } /** * @author CaoShun * @see 从指定位置文件中,读指定一行数据 * */ public static String readInputByRow(String path,int num) { File file=new File(path);try { FileInputStream fis = new FileInputStream(file);InputStreamReader isr = new InputStreamReader(fis, "UTF-8");BufferedReader reader = new BufferedReader(isr);String tempstring="";int line=1;while((tempstring=reader.readLine())!=null) { if(line==num){ break;} line++;} reader.close();isr.close();fis.close();return tempstring;} catch (IOException e) { e.printStackTrace();return null;} } 收起