IO编程——复制一个文件中的内容到另一个文件
public class TestIO {
public static void main(String[] args) {
File inputFile = new File("a.txt");//这个地方要考虑到a.txt和b.txt在项目中的位置
File outputFile = new File("b.txt");
//b.txt文件不存在,可以创建
if(outputFile.exists()){
}else{
try {
outputFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
InputStream inputStream = null;
OutputStream outputStream = null;
int temp;
try {
inputStream = new FileInputStream(inputFile);
outputStream = new FileOutputStream(outputFile);
//读取a.txt数据并写到b.txt文件中
while((temp = inputStream.read()) != -1){
outputStream.write(temp);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
Runtime.getRuntime().exit(-1);
} catch(IOException e){
e.printStackTrace();
} finally{
try{
//一定要关闭,否则可能得不到结果
inputStream.close();
outputStream.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
IO编程——复制一个文件中的内容到另一个文件的更多相关文章
- 将一个文件中的内容,在另一个文件中生成. for line in f1, \n f2.write(line)
将一个文件中的内容,在另一个文件中生成. 核心语句: for line in f1: f1中的所有一行 f2.write(line) ...
- 根据Excel文件中的内容,修改指定文件夹下的文件名称
问题:根据Excel文件中内容,把文件名称由第2列,改为第1列.比如:把文件“123.jpg”修改为“1.jpg”.
- Flex读取txt文件中的内容(二)
Flex读取txt文件中的内容 自动生成的文件 LoadTxt-app.xml: <?xml version="1.0" encoding="utf-8" ...
- Java IO把一个文件中的内容以字符串的形式读出来
代码记录(备查): /** * 把一个文件中的内容以字符串的形式读出来 * * @author zhipengs * */ public class FileToString { public sta ...
- java中的文件读取和文件写出:如何从一个文件中获取内容以及如何向一个文件中写入内容
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...
- 代码实现:定义一个文件输入流,调用read(byte[] b)方法,将a.txt文件中的内容打印出来(byte数组大小限制为5)
package com.loaderman.test; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; im ...
- 向txt文件中写入内容(覆盖重写与在末尾续写+FileOutputStream与FileWriter)(转发:https://blog.csdn.net/bestcxx/article/details/51381460)
!!!! 读取txt文件中的内容 import java.io.BufferedReader; import java.io.File; import java.io.FileReader; /** ...
- java代码将excel文件中的内容列表转换成JS文件输出
思路分析 我们想要把excel文件中的内容转为其他形式的文件输出,肯定需要分两步走: 1.把excel文件中的内容读出来: 2.将内容写到新的文件中. 举例 一张excel表中有一个表格: 我们需要将 ...
- iOS案例:读取指定txt文件,并把文件中的内容输出出来
用到的是NSString中的initWithContentsOfFile: encoding方法 // // main.m // 读取指定文件并输出内容 // // Created by Apple ...
随机推荐
- ZOJ2599:Graduated Lexicographical Ordering(很经典的数位DP)
Consider integer numbers from 1 to n. Let us call the sum of digits of an integer number its weight. ...
- 线段树专题 POJ3468 A Simple Problem with Integers
题意:n个点.m个操作.两种操作类型.C X Y K 表示区间[x,y]上每一个点值加k.Q X Y 求区间[x,y]的和 分析:线段树区间求和,裸模板 注意:结果会超int,要用long long ...
- Codeforces Round #273 (Div. 2) B . Random Teams 贪心
B. Random Teams n participants of the competition were split into m teams in some manner so that e ...
- sql server数据库添加记录
转自:http://jingyan.baidu.com/article/f25ef254449a9a482c1b8293.html
- 懒人学习automake, Makefile.am,configure.ac
已经存在Makefile.am,如何生成Makefile? 步骤: [root@localhost hello]# autoscan .///在当前文件夹中搜索 [root@localhost hel ...
- 什么是IaaS,PaaS和SaaS及其区别
云计算的三种服务模式:IaaS,PaaS和SaaS Infrastructure(基础设施)-as-a-Service,Platform(平台)-as-a-Service,Software(软件)-a ...
- java enum int String 相互转换
1. enum<->int enum -> int: int i = enumType.value.ordinal(); int -> enum: enumType b= e ...
- [Swift通天遁地]五、高级扩展-(7)UIView(视图类型)的各种扩展方法
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Jquery 《不想工作系列》--整理一下append、prependTo、after的区别
还有其他类似方法,以后再加,直接上代码和图 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" &q ...
- OFDM同步算法之Schmidl算法
Schmidl算法代码 算法原理 训练序列结构 T=[A A],其中A表示复伪随机序列PN,进行N/2点ifft变换得到的符号序列 \[M(d)=\frac{\left | P(d) \right | ...