房天下 > 房天下问答 > 业主生活 > 其他
  • Java读写txt文件(来自长春标点小区)

    现在已经实现输入一个英文单词,能够输出它在一个字典中对应的序号现在读入一篇txt格式的英文文章,要求把各种标点符号去掉后,读出txt格式文件,里面是按顺序读出的每个单词对应的序号。

    提问者:czhnig

    发布于2010-10-17

共1个回答
  • 江山好的很 丨Lv 0
    给你我写的两个方法!!作为参考吧! /** * @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; } }
    +10 2010-10-17 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。