fp = open('D://代码开发//Python.path//jhp//fadd.txt', 'r') #指定文件
s = fp.read() #将指定文件读入内存
fp.close() #关闭该文件
a = s.split('\n')
a.insert(-1, 'a new line') #在第 LINE+1 行插入
s = '\n'.join(a) #用'\n'连接各个元素
fp = open('D://代码开发//Python.path//jhp//fadd.txt', 'w')
fp.write(s)
fp.close()
结果:
"properties":{
"zookeeper.connect":"zookeeper.com:2015",
"druid.discovery.curator.path":"/druid/discovery",
"druid.selectors.indexing.serviceName":"druid/overlord",
"commit.periodMillis":"12500",
"consumer.numThreads":"1",
"kafka.zookeeper.connect":"kafkaka.com:2181,kafka.com:2181,kafka.com:2181",
"kafka.group.id":"test_dataSource_hod_dd"
a new line
}