Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:拼音特殊字符不输出 import java.io.*; 导入java.util.HashMap; 导入java.util.Map; 导入java.util.Scanner; 导入java.util.TreeMap; 公共类文本阅读器{ 公共静态void main(字符串[]args)抛出FileNotFoundException{ //HashMap HashMap=newhashmap(); TreeMap hashmap=newtreemap(); //获取文件并将其放入file变量中 File File=新文件(“/Desktop/TextSampleWordCount.txt”); //在中扫描文件 扫描仪pinyintextfile=新扫描仪(文件“UTF-8”); while(pinyintextfile.hasNext()){ String word=pinyintextfile.next(); if(hashmap.containsKey(word)){ //如果找到了这个词,我们就把它放到地图上并更新它的计数。 int count=hashmap.get(word)+1; hashmap.put(字,计数); } 否则{ //如果单词不在地图中,我们要为它创建一个新条目 hashmap.put(word,1); } } pinyintextfile.close(); for(Map.Entry:hashmap.entrySet()){ 系统输出打印项次(输入); } } }_Java_Character Encoding_Java.util.scanner - Fatal编程技术网

Java:拼音特殊字符不输出 import java.io.*; 导入java.util.HashMap; 导入java.util.Map; 导入java.util.Scanner; 导入java.util.TreeMap; 公共类文本阅读器{ 公共静态void main(字符串[]args)抛出FileNotFoundException{ //HashMap HashMap=newhashmap(); TreeMap hashmap=newtreemap(); //获取文件并将其放入file变量中 File File=新文件(“/Desktop/TextSampleWordCount.txt”); //在中扫描文件 扫描仪pinyintextfile=新扫描仪(文件“UTF-8”); while(pinyintextfile.hasNext()){ String word=pinyintextfile.next(); if(hashmap.containsKey(word)){ //如果找到了这个词,我们就把它放到地图上并更新它的计数。 int count=hashmap.get(word)+1; hashmap.put(字,计数); } 否则{ //如果单词不在地图中,我们要为它创建一个新条目 hashmap.put(word,1); } } pinyintextfile.close(); for(Map.Entry:hashmap.entrySet()){ 系统输出打印项次(输入); } } }

Java:拼音特殊字符不输出 import java.io.*; 导入java.util.HashMap; 导入java.util.Map; 导入java.util.Scanner; 导入java.util.TreeMap; 公共类文本阅读器{ 公共静态void main(字符串[]args)抛出FileNotFoundException{ //HashMap HashMap=newhashmap(); TreeMap hashmap=newtreemap(); //获取文件并将其放入file变量中 File File=新文件(“/Desktop/TextSampleWordCount.txt”); //在中扫描文件 扫描仪pinyintextfile=新扫描仪(文件“UTF-8”); while(pinyintextfile.hasNext()){ String word=pinyintextfile.next(); if(hashmap.containsKey(word)){ //如果找到了这个词,我们就把它放到地图上并更新它的计数。 int count=hashmap.get(word)+1; hashmap.put(字,计数); } 否则{ //如果单词不在地图中,我们要为它创建一个新条目 hashmap.put(word,1); } } pinyintextfile.close(); for(Map.Entry:hashmap.entrySet()){ 系统输出打印项次(输入); } } },java,character-encoding,java.util.scanner,Java,Character Encoding,Java.util.scanner,程序计算拼音单词的重复次数。问题是,当它输出文本时,它会将其作为 Ch?ng=1 Zh?=3 等等。。。。我试着查找这个问题,但没有任何帮助。我也提到了这一点,并更改了charsetName,但仍然输出问号。我不确定我做错了什么。可能是我的IDE吗 文件看起来像这样 Yùkùsùdǎoúzhǐbìshùmùqiēng zìběn Yáng qīYán biǎo。杜志明·莱恩·维恩·尤扎伊·什卡恩·塞卢·什莱奥·齐齐奥·徐齐安·莫瓦恩。席上的一席一代。Wén sēn déyìfāhùluòzhuǎ

程序计算拼音单词的重复次数。问题是,当它输出文本时,它会将其作为

Ch?ng=1

Zh?=3

等等。。。。我试着查找这个问题,但没有任何帮助。我也提到了这一点,并更改了charsetName,但仍然输出问号。我不确定我做错了什么。可能是我的IDE吗

文件看起来像这样


Yùkùsùdǎoúzhǐbìshùmùqiēng zìběn Yáng qīYán biǎo。杜志明·莱恩·维恩·尤扎伊·什卡恩·塞卢·什莱奥·齐齐奥·徐齐安·莫瓦恩。席上的一席一代。Wén sēn déyìfāhùluòzhuǎn quán dáo nián měi jìshìchūgu géshū。这是一个很好的席。她说:“我不知道你是谁。杜什奥·雷杰奇·舒舒杰恩·尼杰奇·祖克辛。蒂什宁·苏尼昂·尼昂·齐什昂·祖恩·苏尼昂。这很可能是Eclipse控制台设置的配置。检查运行>运行配置>公共(选项卡)>编码,查看默认编码是否为“UTF-8”。如果没有,请选择“UTF-8”作为默认编码,然后再次运行程序


可能是您的IDE在默认情况下不显示unicode字符,您需要启用它。你的IDE是什么?另一个问题:您的输入文本文件是什么样子的?它是用UTF-8编码的吗?@Wickoo我想它可能是IDE im使用eclipse,我会添加这个文件。
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class TextReader {

public static void main(String[] args) throws FileNotFoundException{ 

    //  HashMap<String, Integer> hashmap = new HashMap <String, Integer>();
        TreeMap<String, Integer> hashmap = new TreeMap<String, Integer>();
    //get the file and put it into the file variable    
        File file = new File ("/Desktop/TextSampleWordCount.txt");
    //Scan the file in  
        Scanner pinyintextfile = new Scanner (file,"UTF-8");



         while(pinyintextfile.hasNext()){
             String word = pinyintextfile.next();
             if( hashmap.containsKey(word)){
                 //if the word is found we put the word into the map and update its count. 
                 int count = hashmap.get(word) + 1;
                 hashmap.put(word, count);

             }
             else{
                 //if the word in not in the map we want to create a new entry for it 
                 hashmap.put(word, 1);

             }

         }

             pinyintextfile.close();
             for(Map.Entry<String, Integer> entry : hashmap.entrySet()){
                 System.out.println(entry);
             }  
    }
}