2013年10月1日星期二

File Copy garbled

FileInputStream fis = new FileInputStream ("b.txt");
InputStreamReader isr = new InputStreamReader (fis);
FileOutputStream fos = new FileOutputStream ("copy_b.txt");
OutputStreamWriter osw = new OutputStreamWriter (fos);

int i = -1;
while ((i = isr.read ())! = -1) {
System.out.print ((char) isr.read ());
osw.write (i);
}
isr.close ();
osw.close ();
garbled after copying files , please help me find where the problem is , thank you !
------ Solution ---------------------------------------- ----

Reader r = new BufferedReader(new InputStreamReader(in, System.getProperty("file.encoding")));
Writer w = new BufferedWriter(new OutputStreamWriter(out, System.getProperty("file.encoding")));

------ Solution ------------------------------ --------------
brother, you write that i
not a byte array. . .
------ Solution ---------------------------------------- ----

InputStreamReader 's read () method returns a character .

landlord code reads a character determine whether -1 , discarded, read a write to the output stream.
------ Solution ---------------------------------------- ----
read char, there is the character set problem ,

use ByteArrayInputStream read byte like
------ Solution ------------------------ --------------------

the transferFrom or directly using FileChannel copy
------ For reference transferTo only ---------------------------------------
thank every novice and give you embarrassed
------ For reference only ----------------------------- ----------
Thank you for your answer sincerely thank

没有评论:

发表评论