首页 > 代码库 > python二进制读写文件

python二进制读写文件

#coding=gbk‘‘‘Created on 2014-5-7‘‘‘import os.pathinputPath = ./input.txtoutPath = ./out.txtbufferSize = 10inputFile = open(inputPath, rb)outFile = open(outPath, wb+)fileSize  = os.path.getsize(inputPath)readedSize = 0while readedSize < fileSize -  bufferSize :        tmp = inputFile.read(bufferSize)    outFile.write(tmp)    readedSize = readedSize + bufferSize#读取剩下的部分tmp = inputFile.read(fileSize % bufferSize)outFile.write(tmp)inputFile.close()outFile.close()       print done