FileInputStream fin;
FileOutputStream fout;

try{
try{
fin=new FileInputStream("E:\\ayy\\test2\\Hellojava.txt");//args[0];//这里的txt文件里英文字母后面跟有汉字的,
}catch(FileNotFoundException e){
System.out.println("Input File Not Found...");
return;
}
try{
fout=new FileOutputStream("E:\\ayy\\test2\\Hellojava_Copy.txt");//args[1];
}catch(FileNotFoundException e){
System.out.println("Output File Not Found...");
return;
}
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Usage: CopyFile From To");
return;
}

try{
do{
i=fin.read();
if(i!=-1)fout.write(i);
System.out.print((char)i);//读取的时候txt文件中的汉字就变?了,该怎么处理
for(int t=10000000;t>0;t--){};//这里有让线程睡眠几秒的方法码?相当于sleep(1000)这种效果FileInputStream fin;
FileOutputStream fout;

try{
try{
fin=new FileInputStream("E:\\ayy\\test2\\Hellojava.txt");//args[0];
}catch(FileNotFoundException e){
System.out.println("Input File Not Found...");
return;
}
try{
fout=new FileOutputStream("E:\\ayy\\test2\\Hellojava_Copy.txt");//args[1];
}catch(FileNotFoundException e){
System.out.println("Output File Not Found...");
return;
}
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("Usage: CopyFile From To");
return;
}

try{
do{
i=fin.read();
if(i!=-1)fout.write(i);
System.out.print((char)i);
for(int t=10000000;t>0;t--){};
}while(i!=-1);
}catch(IOException e){
System.out.println("File Error...")
}while(i!=-1);
}catch(IOException e){
System.out.println("File Error...");

解决方案 »

  1.   


    for(int t=10000000;t>0;t--){};//这里有让线程睡眠几秒的方法码?相当于sleep(1000)这种效果Thread.sleep(1000);
      

  2.   

    public void fileReadTest(String fn) throws FileNotFoundException, IOException
    {
    BufferedReader br = new BufferedReader(new FileReader(fn));

    String str = br.readLine();

    while (str != null)
             {
                  str += br.readLine();
             } System.out.println(str);
    }这样就可以读中文了.
      

  3.   

    to:lei198203(lei)
    我是想让它遇到字母的时候显示字母,遇到汉字的时候显示汉字,这样可以实现吗?
      

  4.   

    String str = br.readLine();

    while (str != null)
             {
               str += br.readLine();
              str= new String(str .getBytes("ISO-8859-1"),"GBK");//转换中文,加上这句
             }
      

  5.   

    i=fin.read();
    if(i!=-1)fout.write(i);
    System.out.print((char)i);
      

  6.   

    i=fin.read();
    if(i!=-1)fout.write(i);
          System.out.print((char)i);
    i返回的是读文件的长度,是int类型,用(char)i转换,当然是你不认识的字符了。
    应修改为:
    Byte[] b = new Byte[1024];
    i=fin.read(b);
    if(i!=-1)fout.write(i);
          System.out.print(new String(b,0,i));
    就可以了。
    Thread.sleep(1000);可以让线程睡1秒钟。
      

  7.   

    try {
          BufferedReader br = new BufferedReader(
              new InputStreamReader(
              new FileInputStream("d:\\message.properties"),"gb2312"));
          StringBuffer sb=new StringBuffer();
          String tmp=br.readLine();
          while (tmp!=null)
          {
            sb.append(tmp);
            tmp=br.readLine();
          }
          br.close();
          br=null;
          System.out.println(""+sb.toString());
        }catch (Exception ex)
        {
          ex.printStackTrace();
        }
      

  8.   

    TO:linus_lee(会游泳的鱼) 
    这里加了Byte[]怎么用呢
      

  9.   

    上面的上面说的对。
    stream 是字节流。
    会出现汉字乱麻。
      

  10.   

    /*
     * 入力ストリームをバッファリング
     */
    BufferedInputStream inBuffer = new BufferedInputStream(is); DataInputStream dataInStream = new DataInputStream(inBuffer); String fileName = fileUp.getFileName();

    String fileKind = (fileName.substring(fileName.indexOf(".") + 1))
    .toLowerCase();
    String str;
    int row = 0;

    csvDataBeanList.clear();


    if (dataInStream.readLine() == null) {
    inBuffer.close();
    dataInStream.close();
    fileUp.destroy();

    ActionMessages messages = new ActionMessages();
    ActionMessage msg = new ActionMessage("message.6260");
    messages.add(ActionMessages.GLOBAL_MESSAGE, msg);
    saveMessages(req, messages);
    return;
    }
      

  11.   

    乱码可能和OS系统,系统字符集,操作的对象的处理方式,操作对象的编码有关系.你可以多些DEBUG看看到哪里出来就是乱码了?一步步的往源头找