Android Log引发的血案

有时候写程序跟小时候做数学题一样粗心。

今天写了个demo,Socket收发文件的,结果客户端只收到50%的文件内容。

纠结了半天,才发现错误代码:

				while (true) {
					int read = 0;
					if (fis != null) {
						read = fis.read(buf);
						LogTrace.d(TAG, "doInBackground", "read = "+fis.read(buf));
					}
					passedlen += read;
					if (read == -1) {
						break;
					}
					
					System.out.println("文件传送了 passedlen:" + passedlen);
					System.out.println("文件传送了" + (passedlen * 100 / len) + "%\n");
					ps.write(buf, 0, read);
				}
				ps.flush();

LogTrace.d(TAG, "doInBackground", "read = "+fis.read(buf));

读了2次。。。。。

记录!!!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章