package com.soecode.lyf.web.test;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class FileCopy {
/*如果操作文件是纯文本则使用字符流,如果不是纯文本则使用字节流*/
public static void main(String[] args) {
//向文件中写入数据(会把原来的数据覆盖掉)
//writeFile();
//按照单个字符读取
//readByCharacter();
//按照字符组读取
//readByCharacterArray();
//对已存在的文件进行续写(不会覆盖原来的数据但是,只能写一次)
//writeFileContinue();
//将F盘的文件拷贝到D盘
//copyFileFromFtoD();
//字符缓冲流的读取
/*缓冲区的出现时为了提高流的操作效率而出现的.
需要被提高效率的流作为参数传递给缓冲区的构造函数
在缓冲区中封装了一个数组,存入数据后一次取出*/
/*读取的内容是:
窗前明月光,疑是地上霜。
举头望明月,低头思故乡。
--李白*/
//bufferedReader();
//字符缓冲流的写
//bufferedWriter();
//媒体流的时候就会用到字节流
//将F盘的图片拷贝到D盘
//copyPictureFromDtoF();
//将F盘的音乐复制到D盘
//copyMP3FromFtoD();
}
private static void copyMP3FromFtoD() {
FileInputStream fi = null;
FileOutputStream fo = null;
try {
fi = new FileInputStream("F:\\aa\\guoge.mp3");
fo = new FileOutputStream("D:/guoge_copy.mp3");
byte[] buf = new byte[1024];
int n=0;
while((n=(fi.read(buf)))!=-1){
fo.write(buf, 0, n);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
fo.close();
fi.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void copyPictureFromDtoF() {
FileInputStream fi = null;
FileOutputStream fo = null;
try {
fi = new FileInputStream("F:\\aa\\004.png");
fo = new FileOutputStream("D:\\004_copy.png");
byte[] buf = new byte[1024];
int n=0;
while((n=fi.read(buf))!=-1){
fo.write(buf, 0, n);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
fo.close();
fi.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void bufferedWriter() {
FileWriter file = null;
BufferedWriter bw = null;
try {
file = new FileWriter("F:\\aa\\bb.txt",true);
bw = new BufferedWriter(file);
//跨平台的换行符
bw.newLine();
bw.write("天行健,君子以自强不息;");
bw.newLine();
bw.write("地势坤,君子以厚德载物。");
bw.newLine();
//缓冲区的写必须有刷新
bw.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
bw.close();
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void bufferedReader() {
FileReader file = null;
try {
file = new FileReader("F:\\aa\\bb.txt");
BufferedReader br = new BufferedReader(file);
while(true){
String s;
try {
s = br.readLine();
if(s==null)break;
System.out.println(s);
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally{
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void copyFileFromFtoD() {
FileWriter fw = null;
FileReader fr = null;
try {
fw = new FileWriter("D:\\test20180224.txt",true);
fr = new FileReader("F:\\aa\\test.txt");
char[] buf = new char[11];
int n=0;
while((n=fr.read(buf))!=-1){
fw.write(new String(buf, 0, n));
System.out.println(new String(buf, 0, n));
}
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
fw.close();
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void writeFileContinue() {
FileWriter file = null;
try {
file= new FileWriter("F:\\aa\\test.txt",true);
file.write("(这是续写内容)");
file.flush();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void readByCharacter() {
FileReader file = null;
try {
//创建FileReader并指定要读取的文件
file = new FileReader("F:\\aa\\test.txt");
int n =0;
while((n=file.read())!=-1){
System.out.println((char)n);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void readByCharacterArray() {
FileReader file = null;
try {
//创建FileReader并指定要读取的文件
file = new FileReader("F:\\aa\\test.txt");
char[] buf = new char[11];
int n =0;
while((n=file.read(buf))!=-1){
System.out.println(new String(buf,0,n));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static void writeFile() {
//创建一个FileWriter对象,该对象初始化的时候就要指定被操作的文件 该文件不存在就会新建一个文件
FileWriter file = null;
try {
file = new FileWriter("F:\\aa\\test.txt");
file.write("HelloWorld!");
//刷新缓存数据将数据写入文件
file.flush();
file.write("你好世界!");
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
C语言实现打印出心形,初学者的表白神器。解题思路:这道例题我分了4部分,前3行一部分,4-6行一部分,7-13行一部分,最后一行一部分,读者请仔细阅读注释,小林写的很详细了。前三行输出,为...
k8s中gitlab、jenkins pipeline、harbor CICD项目实战,文章中提供了统一的pipeline微服务模板,和服务chart模板
存储器1. 存储结构概况 2. DRAM和SRAMSRAM 3.主存的工作原理4.主存的技术发展
计算一个字符串中每个字符出现次数。分析:charAt(i) 函数 是获取字符串中i位置的字符可以通过使用 Map 的containsKey() 方法来检测数据(value)是否存在import java.util.HashMap;import java.util.Map;import java.util.Scanner;/** * @author wangtengfei *...
脚本如下#!/bin/bash#Editor:Bertram#Created Date:2020/1/9source /etc/profilePROJECT="/usr/local/tomcat_$1"PID=`ps aux | grep "${PROJECT}"|grep -v "grep"|awk '{print $2}'`if [[ "$PID" -eq 0 ]];then echo "service process is no exist!" $PROJECT/bin
declare 在 Oracle 一般是用在函数、存储过程和块结构及简单的事务中。普通变量声明declare v_number number(10); -- 长度10v_char varchar2(20); -- 长度20带默认值declare v_number number(10) := 10; -- 长度10v_char varchar2(20) := 'ABC'; -- 长度20数组变量在 ...
在packetbeat7.x创建索引时,默认创建的索引名称变为packetbeat-{agentversion}-{date}-00001,并且在第二天未新建新的索引名称,不利于对elasticsearch主机硬盘的管理。在通过各种索引覆盖配置未生效后,在官方文档中找到如下内容:使用Elasticsearch中的索引生命周期管理功能来管理Packetbeat索引的老化. 例如,不是创建索引大小...
Python 输入一个字符串,以回车结束(字符串长度<=100)。该字符串由若干个单词组成,单词之间用一个空格隔开,所有单词区分大小写。现需要将其中的某个单词替换成另一个单词,并输出替换之后的字符串。
Linux下yum已经准备好了,直接下载安装docker其实已经安装过,也用了一段时间了,但是发现每次发布都需要好繁琐,所以想着弄进来Jenkins,结果会有报错,原因是因为笔者的CentOS 7.2使用yum安装docker,导致docker版本只有1.X,而最新版已经超过18.X,所以后来卸载docker使用正确途径安装就解决问题了。其实我安装的时候没想这个版本会差这么多...
一、实验目的熟悉Warshall算法,掌握求关系的自反闭包、对称闭包和传递闭包的方法。二、实验内容定义1 设R是A上的二元关系,R的自反(对称、传递)闭包是关系R1,则① R1是自反的(对称的、传递的)② RR1③对任何自反的(对称的、传递的)关系R2,若RR2,则R1R2。R的自反、对称和传递闭包分别记为r、s和t。定理1 令RAA,则① r=R∪IA② s=R∪R-1③ t=R∪R2∪R3…Warshall算法:设R是n个元素集合上的二元关系,M是R
博主最近开始玩Redis啊~~看了很多Redis的文章,感觉有点云里雾里的,之前看到是ServiceStack.Redis,看了一些大佬封装的Helper类,还是懵懵的QAQ没办法啊只能硬着**上啊开始着手写简单的Demo不同类型的存入、取出,之后写一些简单的封装,由简入繁嘛用过ServiceStack.Redis后发现原来还有一个每小时只能调用...
在python中使用PyPDF2扩展包的PdfFileMerger函数合并pdf时,代码如下:merger = PdfFileMerger()input1 = open(r"2.pdf", "rb")input2 = open(r"3.pdf", "rb")merger.append(input1)merger.append(input2)# Write to an output PDF documentoutput = open(r"1.pdf", "wb")merger.write(ou