我是新手,从网上粘来代码学习用,这段代码在DOS窗口 JAVAC 编译后,出现警告信息,当时没多留意,大概是说会改变系统设置吧,用 JAVA 命令 执行后,中文部分都是乱码了,请各位给个帮助,最好说下怎么改过来,谢谢哦~
- Java code
import java.io.*; public class Test1{ public static void main (String args[]) { try { System.out.print("请输入文件名:"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String filename=br.readLine(); FileInputStream fileIn=new FileInputStream(filename); StreamTokenizer st =new StreamTokenizer(fileIn); st.ordinaryChar(46); st.ordinaryChar(34); int wordCount=0,numCount=0,punctionCount=0,count=0; double token; while ((token=st.nextToken())!=StreamTokenizer.TT_EOF) { count++; if (token==StreamTokenizer.TT_WORD) wordCount++; else if (token==StreamTokenizer.TT_NUMBER) numCount++; else punctionCount++; } System.out.println("单词总数为:"+count); System.out.println("单词数为:"+wordCount); System.out.println("数字数为:"+numCount); System.out.println("标点符号数为:"+punctionCount++); } catch (IOException e) { System.out.println(e.getMessage()); } }}
------解决方案--------------------
我用了下,很正常!
------解决方案--------------------
跟代码没关系,跟CMD窗口的编码设置有关系,自己设置下