#coding=gbk ‘‘‘ Created on 2014-5-7 ‘‘‘ import os.path inputPath = ‘./input.txt‘ outPath = ‘./out.txt‘ bufferSize = 10 inputFile = open(inputPath, ‘rb‘) outFile = open(outPath, ‘wb+‘) fileSize = os.path.getsize(inputPath) readedSize = 0 while 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‘
python二进制读写文件
时间: 2024-10-10 17:32:34