感谢stackoverflow,我能够读取和复制文件。但是,我需要一次读取一个图片文件,并且缓冲区数组不能超过 3000 个整数。我将如何分隔行,阅读它们,然后复制它们?这是执行此操作的最佳方法吗?
这是我的代码,由@Chayim 提供:
import os
import sys
import shutil
import readline
source = raw_input("Enter source file path: ")
dest = raw_input("Enter destination path: ")
file1 = open(source,'r')
if not os.path.isfile(source):
print "Source file %s does not exist." % source
sys.exit(3)
file_line = infile.readline()
try:
shutil.copy(source, dest)
infile = open(source,'r')
outfile = open(dest,'r')
file_contents = infile.read()
file_contents2 = outfile.read()
print(file_contents)
print(file_contents2)
infile.close()
outfile.close()
except IOError, e:
print "Could not copy file %s to destination %s" % (source, dest)
print e
sys.exit(3)
我添加了 file_line = infile.readline() 但我担心 infile.readline() 将返回一个字符串,而不是整数。另外,我如何限制它处理的整数数量?