• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 40, 文章 - 0, 評論 - 19, 引用 - 0
            數據加載中……

            Java實驗之簡易通訊錄

            Java對文件進行了讀寫操作,信息存儲在phonesnumber.txt里面

            //Main.java
            package exp5_5;

            import java.io.IOException;

            public class Main {

                
            /**
                 * 
            @throws IOException 
                 * @Hadn't 2010-4-23
                 
            */


                
            public static void main(String[] args) throws IOException {
                    addresslist read 
            = new addresslist("phonesnumber");
                    read.show();
                }


            }

            //people.java
            package exp5_5;

            public class people {
                
            private String PhoneNum;
                
            private String Name;
                
            private int No;
                
            public people(String Name ,String PhoneNum,int No){
                    
            this.Name = Name;
                    
            this.PhoneNum = PhoneNum;
                    
            this.No = No;
                }

                
            public String get_Name(){
                    
            return this.Name;
                }

                
            public String get_PhoneNum(){
                    
            return this.PhoneNum;
                }

                
            public int get_No(){
                    
            return this.No;
                }

            }

            //addresslist.java
            package exp5_5;

            import java.io.File;
            import java.io.FileNotFoundException;
            import java.io.FileWriter;
            import java.io.IOException;
            import java.util.Scanner;


            /**
             * @Hadn't 2010-4-22
             
            */

            public class addresslist {
                
            private int Num;
                File fileadd;    
                
            public addresslist(String fileadd) throws IOException{
                    
            this.fileadd = new File(fileadd+".txt");    
                        
            if((!this.fileadd.exists())){
                            
            this.fileadd.createNewFile();
                        }

                        
            else{
                            Scanner read 
            = new Scanner(this.fileadd);
                            
            this.Num  = 0;
                            
            while(read.hasNext()){
                                
            for(int i = 0 ; i < 3 ; i++ )
                                    read.next();
                                
            this.Num++;
                            }

                        }

                    }
                
                
            public boolean insert(people per) throws IOException{    
                    
            // 保存    
                    FileWriter writer = new FileWriter(this.fileadd,true);    
                    writer.write(per.get_No()
            +" "+per.get_Name()+" "+per.get_PhoneNum()+"\n");
                    writer.close();
                    
            return true;
                }

                
            public void show() throws FileNotFoundException{
                    
            while(true){
                        
            // wait
                        Scanner read = new Scanner(this.fileadd);
                        
                        
            int i = 0;
                        
            while(read.hasNext()){
                            System.out.println(
            "No."+read.next()+"  姓名:"+read.next()+"   電話號碼:"+read.next());
                            i
            ++;
                        }

                        System.out.println(
            "目前記錄總數:"+i);
                        
            // show
                        System.out.println("退出輸入exit,插入數據輸入1");
                        Scanner cin 
            = new Scanner(System.in);            
                        String get 
            = cin.nextLine();            
                        
            if(get.equals("exit")){            
                            
            break;                
                        }

                        
            else if(get.equals("1")){
                            System.out.println(
            "請輸入姓名,不要輸入非法字符或空格");
                            String Name 
            = cin.next();
                            System.out.println(
            "請輸入電話號碼,不要輸入非法字符或空格");
                            String PhoneNumber 
            = cin.next();
                            people a 
            = new people(Name,PhoneNumber,this.Num++);                    
                            
            try {
                                insert(a);
                            }
             catch (IOException e) {                    
                                e.printStackTrace();
                            }

                        }
                        
                    }
                    
                }

            }

            posted on 2010-04-26 21:20 hadn't 閱讀(595) 評論(2)  編輯 收藏 引用

            評論

            # re: Java實驗之簡易通訊錄  回復  更多評論   

            當年的大作業啊……
            2010-04-27 08:17 | 陳梓瀚(vczh)

            # re: Java實驗之簡易通訊錄  回復  更多評論   

            @陳梓瀚(vczh)
            呵呵 Java入門~ 見笑啦~ 拜閱了貴博 希望有機會能與您多交流向您學習
            2010-04-27 10:44 | hadn't
            一97日本道伊人久久综合影院| 日韩人妻无码一区二区三区久久99 | 狠狠色丁香婷婷久久综合五月| 中文字幕久久精品| 无码人妻久久一区二区三区免费| 久久国产精品99国产精| 思思久久99热免费精品6| 77777亚洲午夜久久多喷| 久久夜色撩人精品国产小说| 国产精品久久久天天影视| 一本久久免费视频| 91久久精品视频| 国产精品一久久香蕉产线看| 99久久香蕉国产线看观香| 91精品国产高清久久久久久91| 久久精品国产亚洲AV影院| 久久国产综合精品五月天| 国产精品对白刺激久久久| 亚洲AV无码久久| 亚洲精品乱码久久久久久中文字幕 | 97久久精品人人澡人人爽| 久久久久无码精品国产不卡| 久久久精品无码专区不卡| 99久久国产主播综合精品| 欧美伊香蕉久久综合类网站| 99久久免费国产特黄| 久久久av波多野一区二区| 久久久国产视频| 中文成人久久久久影院免费观看| 久久国产成人| 久久se精品一区二区影院| 久久国产V一级毛多内射| 久久国产成人午夜aⅴ影院| 国产三级精品久久| 日韩十八禁一区二区久久| 66精品综合久久久久久久| 国产激情久久久久影院老熟女免费| 国产成人无码精品久久久久免费| 久久天堂电影网| 四虎国产永久免费久久| 久久久久久毛片免费看|