博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
单词频率
阅读量:4612 次
发布时间:2019-06-09

本文共 3602 字,大约阅读时间需要 12 分钟。

第一次学习如何从文件中读取,在网上学习的也差不多了,然后就接着学习如何导入到文件中,总结出来就是自己看不懂代码,这次遇到了极大的困难,本来C和C++文件这一部分就没有学,Java于是就更突出了,然后统频率也是困难重重,我大概计算了下时间,用了4个小时竟然什么都没有做出来,这次真的是听郁闷的,以后还是要多多学习,现在Java的代码还是有很多都是看不懂,真的是受打击了。

下面是这次写的代码:

1 package DaoRu;  2 import java.io.*;  3 import java.util.HashMap;  4 import java.util.regex.Matcher;  5 import java.util.regex.Pattern;  6 public class DaoRu {  7     public static void main(String[] args) {           8        //读取D盘的file1文件  9        File file = new File("D://file1.txt"); 10        BufferedInputStream bis = null; 11        FileInputStream  fis= null; 12        try 13        { 14            //第一步 通过文件路径来创建文件实例 15            fis = new FileInputStream(file); 16            /*把FileInputStream实例 传递到 BufferedInputStream 17              目的是能快速读取文件 18             */ 19            bis = new BufferedInputStream(fis); 20            /*available检查是不是读到了文件末尾 */ 21            while( bis.available() > 0 ){                  22                System.out.print((char)bis.read()); 23            } 24         }catch(FileNotFoundException fnfe) 25          { 26              System.out.println("文件不存在" + fnfe); 27          } 28          catch(IOException ioe) 29          { 30              System.out.println("I/O 错误: " + ioe);  31          } 32          finally 33          { 34              try{ 35                 if(bis != null && fis!=null) 36                 { 37                       fis.close(); 38                    bis.close(); 39                 }       40               }catch(IOException ioe) 41                { 42                    System.out.println("关闭InputStream句柄错误: " + ioe); 43                }          44          } 45     } 46 } 47 package DaoChu; 48 import java.io.FileNotFoundException; 49 import java.io.FileWriter; 50 import java.io.IOException; 51   52 public class ShuRu { 53     public static void rwFile(){ 54         FileWriter fw = null; 55         try { 56             fw = new FileWriter("D:\\file2.txt", true); 57                 fw.write("aaaaa");//这里向文件中输入结果123 58                 fw.flush(); 59         } catch (FileNotFoundException e) { 60             e.printStackTrace(); 61         } catch (IOException e) { 62             e.printStackTrace(); 63         } finally { 64             if (fw != null) { 65                 try { 66                     fw.close(); 67                 } catch (IOException e) { 68                     // TODO Auto-generated catch block 69                     e.printStackTrace(); 70                 } 71             } 72         } 73     } 74     public static void main(String[] args) { 75         rwFile(); 76     } 77 } 78 package Dictionary; 79  import java.util.*; 80  import java.util.regex.*; 81  public class Dictionary{ 82      public static void main(String[] args){ 83          String words = "Look buddy, U got work hard and put yourself in your java, Once you learned the heart of the java, I can guarantee that you win."; 84          String reg = "[a-zA-Z]+"; 85          Pattern p = Pattern.compile(reg); 86          Matcher m = p.matcher(words); 87          HashMap
map = new HashMap
(); 88 int count = 0; 89 while(m.find()){ 90 count++; 91 String w = m.group(); 92 if(null == map.get(w)){ 93 map.put(w, 1); 94 }else{ 95 int x = map.get(w); 96 map.put(w, x + 1); 97 } 98 } 99 System.out.println(count);100 System.out.println(map);101 }102 }

 

 
 

转载于:https://www.cnblogs.com/qianmo123/p/9774915.html

你可能感兴趣的文章
监控级联时各个层的PoE交换机怎么选?
查看>>
存储过程
查看>>
ADO.NET--SqlConnection、SqlCommand的学习
查看>>
PCA降维处理
查看>>
random模块
查看>>
CSS3 新属性兼容性测试
查看>>
js闭包
查看>>
Oralce导入数据库出现某一列的值太大
查看>>
Union和Union All 的区别
查看>>
Git的安装和使用教程详解
查看>>
lsof命令详解
查看>>
常用模块,异常处理
查看>>
父窗口与子窗口之间的传值
查看>>
eclipse 找不到 tomcat 的解决方案
查看>>
HDU 1890--Robotic Sort(Splay Tree)
查看>>
connection string for Excel/Access 2010
查看>>
【转】【Python】Python中的__init__.py与模块导入(from import 找不到模块的问题)
查看>>
学习wavenet_vocoder之环境配置
查看>>
常用Maven命令
查看>>
Docker启动mysql的坑2
查看>>