文件A的内容复制到B

以下脚本摘自笨学python,个人添加了备注

------------------------------------------------------------

1、脚本

from sys import argv
from os.path import exists
script,from_file,to_file = argv
print("Copy file %s to file %s" %(from_file,to_file))
#以读的方式打开from_file
in_file = open(from_file,"r")
#将in_file文档的内容读取出来
indata = in_file.read()
#将in_file文档的内容打印出来
print(indata)

print("the input file is %d bytes long" %len(indata))
print("Does the output file exists? %r" %exists(to_file))
print ("ready,hit RETURN to continue, CTRL-C to abort.")
#以读的方式打开to_file
out_file = open (to_file,‘w‘)
#将indata的内容写入out_file
out_file.write(indata)
#在写入后,再次以读的方式打开to_file
out_file = open(to_file,‘r‘)
#将out_file文档的内容读取出来
outdata = out_file.read()
#将out_file文档的内容打印出来
print(outdata)

out_file.close()
in_file.close()
print("Alright,all done.")

2、执行结果

3、01txt内容为:

原文地址:https://www.cnblogs.com/merry-0131/p/8462383.html

时间: 2024-09-20 19:27:42

文件A的内容复制到B的相关文章

复制多级文件,将一个文件夹中的所有内容复制到另一个文件夹中

复制多级文件,将一个文件夹中的所有内容复制到另一个文件夹中. 设计递归方法,通过传入源文件和目的文件,将源文件中内容完全复制到目的文件中:代码如下: private static void copyFolder(File srcFile, File destFile) throws IOException { //srcFile为源文件,destFile为目的文件 if (srcFile.isDirectory()) { File newFolder = new File(destFile, s

java文件和文件夹的增删复制

在使用java进行开发时经常会用到文件和文件夹的增删复制等方法,我写了一个小工具类,和大家分享,希望大家指正: package com.wangpeng.utill; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.InputStream; import java.io.PrintWrite

android之文件操作——读取assets和raw文件下的内容

1.分别创建assets文件夹和res/raw文件夹:(要注意的raw文件是在res下new,然后创建一个名字为raw的文件夹)        2.创建两个txt文件,复制到asset和raw文件夹中: 3.实现的效果: 4.实现代码: (1)布局文件: 1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.androi

ZeroclipboardJS+flash实现将内容复制到剪贴板实例

Zeroclipboard 的实现原理 Zeroclipboard 利用 Flash 进行复制,之前有 Clipboard Copy 解决方案,其利用的是一个隐藏的 Flash.但最新的 Flash Player 10 只允许在 Flash 上进行操作才能启动剪贴板.所以 Zero Clipboard 对此进行了改进,用了一个透明的 Flash ,让其漂浮在按钮之上,这样其实点击的不是按钮而是 Flash ,也就可以使用 Flash 的复制功能了. 如何使用 Zeroclipboard 首先下载

Java之递归遍历目录,修改指定文件的指定内容

EditProperties.java 1 package PropertiesOperation.Edit; 2 3 import java.io.File; 4 5 /** 6 * 替换指定Porpoerties文件中的指定内容 7 * 三个参数: 8 * filePath:存放properties文件的目录 9 * srcStr:需要替换的字符串 10 * desStr:用于替换的字符串 11 * */ 12 public class EditProperties { 13 private

Linux 124课程 12、文件归档和系统复制

1.使用tar创建新的压缩档案,从现有的档案文件中提取文件 tar 打包/压缩/解压缩 文件: c 创建新的存档 x 提取存档 t 列出存档文件的内容 v 显示详细信息 f 显示文件名 p 提取文档时保留权限 z 使用gzip压缩 压缩较小 j 使用bzip2压缩 压缩较大 J 使用xz压缩 压缩比很大 C 指定解压的目标路径 tar -cvf etc.tar /etc/ 对/etc/目录进行打包 file etc.tar tar -tf etc.tar 查看tar包里面的内容 tar -xvf

创建日志文件并在该文件里添加内容

'创建日志文件并在该文件里添加内容 Sub writelog(log) Const forreading =1,forwriting =2,foraddpending=8 Dim fso,f Dim filepath filepath ="C:\log\log.txt" Set fso =createobject("scripting.filesystemobject") If fso.FileExists(filepath) = false Then Set f

linux命令---查找文件中的内容

linux命令---查找文件中的内容 [[email protected] ~]$ cat 1.txt |egrep '123456789|second'-------匹配123456789或者second的行 first line:123456789012345678901234567890123456789012345678901234567890 second line:one two three four five six seven eight nine ten [[email pro

ZeroMQ接口函数之 :zmq_msg_copy - 把一个消息的内容复制到另一个消息中

ZeroMQ 官方地址 :http://api.zeromq.org/4-1:zmq_msg_copy zmq_msg_copy(3)   ØMQ Manual - ØMQ/3.2.5 Name zmq_msg_copy - 把一个消息的内容复制到另一个消息中 Synopsis int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src); Description zmq_msg_copy()函数会将src指定的消息对象中的内容复制到dest指定的消息对象