cmd运行Java文件输入密码输出txt内容出现乱码

当使用utf-8编码时Java代码中中文输出时出现乱码,输出的txt文件中文字也有部分乱码

img

在改过编码为简体中文(chcp 936)后java代码中中文输出正常,txt文件输出出现乱码

img

代码为

import java. io.*;
public class PassWord{
public static void main(String args[]){
    boolean success=false;
    int count=0;
    Console cons;
    char[] passwd;
    cons=System. console();
    while(true){
                System.out.print("输入密码:");
                passwd=cons.readPassword();
                count++;
                String password=new String(passwd);
                if(password. equals("tiger123")){
                    success=true;
                    System.out.println("您第"+count+"次输入的密码正确!");
                        break;
                }
                else{
                    System.out.println("您第"+count+"次输入的密码"+password+"不正确"); 
                }
                if(count==3){
                    System. out. println("您"+count+"次输入的密码都不正确"); 
                    System. exit(0);
                }
                
    }
    if(success){
        File file=new File("score.txt");
        try {
                FileReader  inOne=new  FileReader (file);
                BufferedReader inTwo =new  BufferedReader(inOne); 
                String s=null;
                while((s=inTwo.readLine())!=null){
                    System. out. println(s);
                }
                inOne.close();
                inTwo.close();
                }
                catch( IOException  exp){
                                
}
    }
}


}


希望各位看看怎么实现中文全部输出正常

修改为utf-8时,txt编码方式也修改为utf-8
文件另存为,可以选择编码方式。

你应该设置你的文件流为 UTF8。

    FileInputStream fis  =   new  FileInputStream( " d:\\input.txt " );
        InputStreamReader isr  =   new  InputStreamReader(fis,  " UTF-8 " );

重新建一个score.txt文件,拷贝内容到新的文件中,保存编码为ANSI。