Python模拟java输入输出流

#!/usr/bin/python
__author__ = 'huangpeng03'


def FileInputStream(filename):
    try:
        f = open(filename)
        for line in f:
            for byte in line:
                yield byte
    except StopIteration as e:
        f.close()


def FileOutputStream(ins, filename):
    try:
        f = open(filename, 'w')
        while True:
            byte = ins.next()
            f.write(byte)
    except StopIteration as e:
        print e

if __name__ == '__main__':
    FileOutputStream(FileInputStream('hello.txt'), 'hello2.txt')

你可能感兴趣的:(Python)