zoukankan      html  css  js  c++  java
  • 加载词库小程序

    //如何向一个UTF-8或者其他编码方式的文档中添加新词  
    //本程序可以添加一个字符串或者添加一个集合
     
     
     
     
    import java.io.BufferedWriter;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;
    
    
    public class AddNewWord {
    	public static OutputStreamWriter osw=null;
    	public static BufferedWriter bw=null;
    	public static String newWord;
    	public static String path;
    	public static ArrayList<String> list;
    	 
    			public void addNewWords(String newWord,String path) 
    			{
    				
    				
    				try {
    					osw=new OutputStreamWriter(new FileOutputStream(path,true),"UTF-8");
    					bw=new BufferedWriter(osw);
    					//bw.newLine();
    					bw.append(newWord);
    					bw.newLine();
    					//System.out.println("写入成功!");
    					
    				} catch (IOException e) {
    					// TODO Auto-generated catch block
    					e.printStackTrace();
    					System.out.println("写入失败");
    				}
    				finally
    				{
    					if (bw!=null)
    					{
    						try {
    							bw.close();
    						} catch (IOException e) {
    							// TODO Auto-generated catch block
    							e.printStackTrace();
    							System.out.println("流关闭失败");
    						}
    					}
    				}
    				
    			}
    		  public void addArraryWords(Collection<String> list,String path)
    		  {
    			  Iterator <String>it=list.iterator();
    			 
    			  while (it.hasNext())
    				  {
    					 
    					try {
    						osw=new OutputStreamWriter(new FileOutputStream(path,true),"UTF-8");
    						bw=new BufferedWriter(osw);
    						//bw.newLine();
    						
    						bw.append(it.next().toString());
    						bw.newLine() ;
    					} catch (IOException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    						System.out.println("多个词语添加失败");
    					}
    					finally
    					{
    						if (bw!=null)
    							try {
    								bw.close();
    							} catch (IOException e) {
    								// TODO Auto-generated catch block
    								e.printStackTrace();
    								System.out.println("流关闭失败");
    							}
    					}
    					 
    				  
    			  }
    		
    		  }
    	      
    }		   

  • 相关阅读:
    python抓取网页图片
    Socket通信之Java学习(一)
    python打包成window可执行程序
    linux下安装java
    SpringBoot系列:五、SpringBoot使用Actuator
    SpringBoot系列:四、SpringBoot集成JPA
    SpringBoot系列:三、SpringBoot中使用Filter
    SpringBoot系列:二、SpringBoot的配置文件
    SpringBoot系列:一、SpringBoot搭建
    .Net Core使用IConfiguration来处理Json文件
  • 原文地址:https://www.cnblogs.com/lixingle/p/3313035.html
Copyright © 2011-2022 走看看