Java使用字符流拷贝文件出现乱码

  1. Java代码
  2. //		BufferedReader in = null;
    //		BufferedWriter out = null;
    		
    		Reader in = null;
    		Writer out = null;
    		
    		try {
    //			in = new BufferedReader(new FileReader(src));
    //			in = new BufferedReader(new InputStreamReader(new FileInputStream(src)));
    //			out = new BufferedWriter(new FileWriter(new File(dir, src.getName())));
    //			out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(dir, src.getName()))));
    			
    			in = new FileReader(src);
    			out = new FileWriter(new File(dir, src.getName()));
    			
    			System.out.println("正在拷贝文件(" + src + ")到目录("+dir+")下");
    			
    			char[] buffer = new char[1024];
    			int len = 0;
    			while((len = in.read(buffer)) != -1) {
    				out.write(buffer, 0, len);
    				out.flush();
    			}
    			
    			return true;
    		} catch (Exception e) {
    			return false;
    		} finally {
    			closeIO(in, out);
    		}


  3. 乱码情况
  4. 怎样解决?
我想知道这种情况是怎么造成的?又该怎样解决?

你可能感兴趣的:(Java)