javaIo文件中添加内容追加String
来源:互联网 发布:知乎win10显示不了桌面 编辑:程序博客网 时间:2024/06/05 15:02
StringBuilder b= new StringBuilder();
package week4HomeWork;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;public class Test {public static void main(String[] args) {File f1= new File("F:\\testio\\a\\a.txt");File f2= new File("F:\\testio\\c\\a.txt");Test.copy(f1,f2);}public static void copy(File f1,File f2){if(!f1.exists()){System.out.println("没有找到文件");}InputStream is =null;OutputStream os =null;try {is=new FileInputStream(f1);os=new FileOutputStream(f2);byte[] b= new byte[1024];int len=0;String strRead="";while((len=is.read(b))!=-1){ strRead=new String(b);}String str= "要添加的字符串";byte[] b1=str.getBytes();if(strRead!=null&&str!=null){if(!(strRead.equals(str))){StringBuilder sb=new StringBuilder();sb.append(str);sb.append(strRead);String str2=sb.toString();byte[] b2=str2.getBytes();os.write(b2);}}} catch (FileNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally{try {is.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}try {os.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}
0 0
- javaIo文件中添加内容追加String
- 文件中追加文本内容
- 向文件中追加内容
- CFile向文件中追加内容
- JAVA向文件中追加内容
- JAVA 向文件中追加内容方法
- php 追加内容到txt文件中
- php 追加内容到txt文件中
- 【Python】往json文件中追加内容
- CStdioFile 追加文件内容
- java追加文件内容
- 追加文件内容
- 向文件中追加内容,然后读取出来
- 打印log等内容到文件中, 追加
- Java中向指定txt文件追加内容
- Android追加换行写入内容到txt文件中
- 追加内容到文件末尾
- 写文件(内容追加)
- 世界杯预测(二) 球队近期状态模型
- 图像平移(translation)运算和镜像(mirror)运算
- 1051. Pop Sequence (25)
- HQL和SQL查询数据的区别
- 【简单】LigthOJ Ekka Dokka 1116
- javaIo文件中添加内容追加String
- C++中explicit关键字解释
- SVM概率输出原理
- JDBC技术学习笔记(一)
- Sql语句 Isnull
- 美好的一天
- Bootstrap Carousel
- Array Two Pointers 总结
- 其实我真的不是来搞笑的(内含java学习笔记)