java输入输出流.doc_第1页
java输入输出流.doc_第2页
java输入输出流.doc_第3页
java输入输出流.doc_第4页
java输入输出流.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

分析成绩单:AnalysisResult.javaimport java.io.*;import java.util.*;public class AnalysisResult public static void main (String args) File fRead = new File(score.txt); /新建一个score.txt文档,父类文件夹选为自己的项目 File fWriter =new File(socreAnalysis.txt); /新建一个socreAnalysis.txt文档,父类文件夹选为自己的项目 try Writer out =new FileWriter(fWriter,true);/以尾加方式创建指向文件fWrite的out流BufferedWriter bufferWrite=new BufferedWriter(out);Reader in =new FileReader(fRead);BufferedReader bufferRead =new BufferedReader(in);String str =null;while(str=bufferRead.readLine()!=null)double totalScore=Fenxi.getTotalScore(str);str =str+ 总分:+totalScore;System.out.println(str);bufferWrite.write(str);bufferWrite.newLine();bufferRead.close();bufferWrite.close();catch (IOException e)System.out.println(e.toString(); Fenxi.javaimport java.util.*;public class Fenxi public static double getTotalScore(String s) Scanner scanner =new Scanner(s); scanner.useDelimiter(0123456789.+); double totalScore=0; while (scanner.hasNext() try double score =scanner.nextDouble(); totalScore=totalScore+score; catch (InputMismatchException exp) String t =scanner.next(); return totalScore; 学习读写汉字:ChineseCharacters.javaimport java.io.*;import java.util.StringTokenizer;public class ChineseCharacters public StringBuffer getChinesecharacters(File file) StringBuffer hanzi=new StringBuffer(); try FileReader inOne=new FileReader(file); /创建指向文件f的inOne 的对象 BufferedReader inTwo=new BufferedReader(inOne); /创建指向文件inOne的inTwo 的对象 String s=null; int i=0; while(s=inTwo.readLine()!=null) /inTwo读取一行 StringTokenizer tokenizer=new StringTokenizer(s, ,n ); while(tokenizer.hasMoreTokens() hanzi.append(tokenizer.nextToken(); catch(Exception e) return hanzi; StudyFrame.javaimport java.awt.*;import java.awt.event.*;import java.io.*;import javax.sound.sampled.*;public class StudyFrame extends Frame implements ItemListener,ActionListener,Runnable ChineseCharacters chinese; Choice choice; Button getCharacters,voiceCharacters; Label showCharacters; StringBuffer trainedChinese=null; Clip clip=null; /本例要求读出的汉字可以发音 Thread voiceThread; int k=0; Panel pCenter; CardLayout mycard; TextArea textHelp; MenuBar menubar; Menu menu; MenuItem help; public StudyFrame() chinese=new ChineseCharacters(); choice=new Choice(); choice.add(training1.txt); choice.add(training2.txt); /新建三个training.txt文档,父类文件夹选为自己的项目 choice.add(training3.txt); showCharacters=new Label(,Label.CENTER); showCharacters.setFont(new Font(宋体,Font.BOLD,72); showCharacters.setBackground(Color.pink); /这块的背景颜色自己改 getCharacters=new Button(下一个汉字); voiceCharacters=new Button(发音); voiceThread=new Thread(this); choice.addItemListener(this); voiceCharacters.addActionListener(this); getCharacters.addActionListener(this); Panel pNorth=new Panel(); pNorth.add(new Label(选择一个汉字字符组成的文件); pNorth.add(choice); add(pNorth,BorderLayout.NORTH); Panel pSouth=new Panel(); pSouth.add(getCharacters); pSouth.add(voiceCharacters); add(pSouth,BorderLayout.SOUTH); pCenter=new Panel(); mycard=new CardLayout(); pCenter.setLayout(mycard); textHelp=new TextArea(); pCenter.add(hanzi,showCharacters); pCenter.add(help,textHelp); add(pCenter,BorderLayout.CENTER); menubar=new MenuBar(); menu=new Menu(帮助); help=new MenuItem(关于学汉字); help.addActionListener(this); menu.add(help); menubar.add(menu); setMenuBar(menubar); setSize(350,220); setVisible(true); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); validate(); public void itemStateChanged(ItemEvent e) String fileName=choice.getSelectedItem(); File file=new File(fileName); trainedChinese=chinese.getChinesecharacters(file); k=0; mycard.show(pCenter,hanzi) ; public void actionPerformed(ActionEvent e) if(e.getSource()=getCharacters) if(trainedChinese!=null) char c=trainedChinese.charAt(k); k+; if(k=trainedChinese.length() k=0; showCharacters.setText(+c); else showCharacters.setText(请选择一个汉字字符文件); if(e.getSource()=voiceCharacters) if(!(voiceThread.isAlive() voiceThread=new Thread(this); try voiceThread.start(); catch(Exception exp) if(e.getSource()=help) mycard.show(pCenter,help) ; try File helpFile=new File(help.txt); FileReader inOne=new FileReader(helpFile); /创建指向文件helpFile的inOne 的对象 BufferedReader inTwo=new BufferedReader(inOne); /创建指向文件inOne的inTwo 的对象 String s=null; while(s=inTwo.readLine()!=null) textHelp.append(s+n); inOne.close(); inTwo.close(); catch(IOException exp) public void run() voiceCharacters.setEnabled(false); try if(clip!=null) clip.close(); clip=AudioSystem.getClip(); File voiceFile=new File(showCharacters.getText().trim()+.wav); clip.open(AudioSystem.getAudioInputStream(voiceFile); catch(Exception exp) clip.start(); voiceCharacters.setEnabled(true); StudyMainClass.javapublic class StudyMainClass public static void main(String args) new StudyFrame(); 统计英文单词:OutputWordMess.javaimport java.util.*;public class OutputWordMess public static void main(String args) Vector allWord,noSameWord; WordStatistic statistic = new WordStatistic(); statistic.setFileName(hello.txt); statistic.wordStatistic(); allWord=statistic.getAllWord(); noSameWord=statistic.getNoSameWord(); System.out.println(共有+allWord.size()+个英文单词); System.out.println(有+noSameWord.size()+个互不相同的英文单词); System.out.println(按出现频率排列:); int count=new intnoSameWord.size(); for (int i=0;inoSameWord.size();i+) String s1 = noSameWord.elementAt(i); for(int j=0;jallWord.size();j+) String s2=allWord.elementAt(j); if (s1.equals(s2) counti+; for (int m=0;mnoSameWord.size();m+)for (int n=m+1;ncountn) String temp=noSameWord.elementAt(n); noSameWord.setElementAt(noSameWord.elementAt(n),n); int t=countn; countn=countn; countn=t; for(int m=0;mnoSameWord.size();m+) double frequency=(1.0*countm)/allWord.size(); System.out.printf(%s:%-7.3f,noSameWord.elementAt(m),frequency); WordStatistic.javaimport java.io.*;import java.util.*;public class WordStatistic Vector allWord,noSameWord;File file = new File(hello.txt); /新建一个hello.txt Scanner sc

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论