技术标签: java Java系列回顾笔记 开发语言
提示:这里可以添加本文要记录的大概内容:
例如:随着人工智能的不断发展,机器学习这门技术也越来越重要,很多人都开启了学习机器学习,本文就介绍了机器学习的基础内容。
提示:以下是本篇文章正文内容,下面案例可供参考
IO流值得是 输入流(Input stream),输出流/(Ouput stream)的简称,是计算机程序用于处理输入和输出的一种抽象的概念
try (InputStream inputStream = Files.newInputStream(Paths.get("path.xml"))) {
// 读取数据的逻辑
} catch (IOException e) {
e.printStackTrace();
}
又或者
Path path=Paths.get("path.xml");
try (InputStream inputStream = Files.newInputStream(path)) {
// 读取数据的逻辑
} catch (IOException e) {
e.printStackTrace();
}
更多的文件操作的方法,比如Files.copy,Files.Move
列子: 将源文件复制到目标文件
try {
Files.copy(Paths.get("path.txt"), Paths.get("test.txt"));
} catch (IOException e) {
e.printStackTrace();
}
支持更多的选项:StandardOpenOption.READ,StandardOpenOption.WRITE等一系列的选项用于打开文件的指定方式,提供了更多的控制性跟灵活性差
Path path=Paths.get("path.xml");
try (InputStream inputStream = Files.newInputStream(path,StandardOpenOption.CREATE)) {
} catch (IOException e) {
e.printStackTrace();
}
//缓冲流读取,它提供了缓冲区来提高读取的性能。通过包装其他输入流,
try (BufferedInputStream bufferedInput = new BufferedInputStream(Files.newInputStream(Paths.get("example.txt")))) {
int data;
while ((data = bufferedInput.read()) != -1) {
System.out.print((char) data);
}
} catch (IOException e) {
e.printStackTrace();
}
// Scanner 类可以方便地用于读取各种数据类型,包括基本类型和字符串
try (Scanner scanner = new Scanner(new FileInputStream("example.txt"))) {
while (scanner.hasNext()) {
String data = scanner.next();
System.out.println(data);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
//从底层输入流中读取基本java数据类型
Path path = Paths.get("example.txt");
try (DataInputStream dataInput = new DataInputStream(Files.newInputStream(path))) {
int data = dataInput.readInt();
System.out.println(data);
} catch (IOException e) {
e.printStackTrace();
}
//是用于读取字符流的类,可以用于读取字符文件的内容
try (FileReader fileReader = new FileReader("example.txt")) {
int data;
while ((data = fileReader.read()) != -1) {
System.out.print((char) data);
}
} catch (IOException e) {
e.printStackTrace();
}
//字符输入流的缓冲,它提供了缓冲区来提高读取字符的性能
try (BufferedReader bufferedReader = new BufferedReader(new FileReader("example.txt"))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
public class ByteArrayInputStream extends InputStream {
/**
* 使用整个字节数组作为输入流
* buf要读取的字节数组
*/
public ByteArrayInputStream(byte[] buf)
/**
* 使用指定区域的字节数组作为输入流
* buf要读取的字节数组
* offset 字符数组的起始偏移量
* length 要读取的字符数
*/
public ByteArrayInputStream(byte[] buf, int offset, int length)
}
//单一读取
ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[1024]);
int data;
while ((data = inputStream.read()) != -1) {
// 处理读取到的字节数据
System.out.print((char) data);
}
// 关闭输入流
try {
inputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
//批量读取
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer, 0, 1024)) != -1) {
// 处理读取到的字节数组数据
System.out.print((char) bytesRead);
}
// 关闭输入流
try {
inputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
try (DataInputStream dataInputStream = new DataInputStream(Files.newInputStream(Paths.get("file.txt")))) {
// 读取不同类型的数据
boolean booleanValue = dataInputStream.readBoolean();
byte byteValue = dataInputStream.readByte();
char charValue = dataInputStream.readChar();
double doubleValue = dataInputStream.readDouble();
float floatValue = dataInputStream.readFloat();
int intValue = dataInputStream.readInt();
long longValue = dataInputStream.readLong();
short shortValue = dataInputStream.readShort();
String stringValue = dataInputStream.readUTF();
} catch (IOException e) {
e.printStackTrace();
}
try (FileReader fileReader = new FileReader("file.txt")) {
int data;
while ((data = fileReader.read()) != -1) {
char character = (char) data;
//输出处理到的数据
System.out.print(character);
}
} catch (IOException e) {
e.printStackTrace();
}
String inputString = "Hello, StringReader,how are you doing!";
try (StringReader stringReader = new StringReader(inputString)) {
char[] buffer = new char[10];
int bytesRead;
while ((bytesRead = stringReader.read(buffer, 0, buffer.length)) != -1) {
// 打印读取到的字符数组数据
System.out.print(new String(buffer, 0, bytesRead));
}
} catch (IOException e) {
e.printStackTrace();
}
String fileName = "file.txt";
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
// 打印读取到的行数据
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
String fileName = "file.txt";
try (InputStream inputStream = Files.newInputStream(Paths.get(fileName));
//指定字符集 将流放到 InputStreamReader中
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
//转成字符流
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
String line;
while ((line = bufferedReader.readLine()) != null) {
// 处理读取到的行数据
System.out.println(line);
}
} catch (IOException e) {
log.info(e.getMessage());
}
String fileName = "file.txt";
try (InputStream inputStream = Files.newInputStream(Paths.get(fileName));
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
// 处理读取到的字节数组数据
System.out.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
log.info(e.getMessage());
}
try (FileOutputStream fileOutputStream = new FileOutputStream("file.txt")) {
// 写入字节数组
byte[] data = "Hello, FileOutputStream!".getBytes();
fileOutputStream.write(data);
// 刷新并关闭流
fileOutputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
try (DataOutputStream dataOutputStream = new DataOutputStream(Files.newOutputStream(Paths.get(fileName)))) {
// 写入基本数据类型
dataOutputStream.writeInt(42);
dataOutputStream.writeDouble(3.14);
dataOutputStream.writeUTF("Hello, DataOutputStream,how are you doing!");
// 刷新并关闭流
dataOutputStream.flush();
} catch (IOException e) {
e.printStackTrace();
}
try (OutputStream outputStream = Files.newOutputStream(Paths.get("file.txt"));
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream)) {
byte[] data = "Hello, BufferedOutputStream!".getBytes(); bufferedOutputStream.write(data);
// 刷新并关闭流
bufferedOutputStream.flush();
} catch (IOException e) {
log.info(e.getMessage());
e.printStackTrace();
}
byte[] data = {
72, 101, 108, 108, 111}; // ASCII codes for 'H', 'e', 'l', 'l', 'o'
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(data)) {
int byteRead;
while ((byteRead = byteArrayInputStream.read()) != -1) {
// 处理读取到的字节
System.out.print((char) byteRead);
}
} catch (IOException e) {
log.info(e.getMessage())
e.printStackTrace();
}
try (OutputStream outputStream = Files.newOutputStream(Paths.get("example.txt"));
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
// 写入字符数据
String data = "Hello, how are you?!";
outputStreamWriter.write(data);
// 刷新并关闭流
outputStreamWriter.flush();
} catch (IOException e) {
log.info(e.getMessage())
e.printStackTrace();
}
try (FileWriter fileWriter = new FileWriter("file.txt")) {
// 写入字符数据
String data = "Hello, how are you?!";
fileWriter.write(data);
// 刷新并关闭流
fileWriter.flush();
} catch (IOException e) {
log.info(e.getMessage());
e.printStackTrace();
}
try (FileWriter fileWriter = new FileWriter("file.txt");
BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)) {
// 写入字符数据
String data = "Hello, how are you?!";
bufferedWriter.write(data);
// 刷新并关闭流
bufferedWriter.flush();
} catch (IOException e) {
log.info(e.getMessage());
e.printStackTrace();
}
try (StringWriter stringWriter = new StringWriter()) {
// 写入字符数据
stringWriter.write("Hello, how are you ?!");
// 获取构建的字符串
String result = stringWriter.toString();
System.out.println(result);
} catch (IOException e) {
log.info(e.getMessage());
e.printStackTrace();
}
提示:java进阶之路学习笔记
文章浏览阅读399次。有谁要是为了赚得更多的钱而加班加点、 更加卖力地去工作, 他就不会真正变得更加富有。 被牺牲掉的业余时间的价值必须从其更高收入中扣除, 而且被牺牲掉的这部分的价值通常比财务上得到的要高很多。为了赚更多的钱而牺牲掉您的业余时间, 靠这种方法您不可能实现真正的富有。 真正的富有是指具有由少变多的本事, 而并非必须为此做出同样程度的牺牲。真正的成功意味着: 您能够获得更高的收入, 但您的...
文章浏览阅读2.2k次。大家好,今天我来分享一下在Linux上运行MySQL服务时遇到的一个插入数据时的报错以及其解决方法。这个报错信息非常具体,相信很多开发者和运维人员都曾经遇到过。记得关注我的公众号“运维家”,获取更多实用技巧和经验分享。一、问题描述当你尝试向MySQL数据库中插入数据时,可能会遇到以下报错信息:“无法插入数据,因为字段不匹配”。这时候,你可能会感到困惑,因为你明明已经按照正确的格式提供了数据,为什么..._mysql数据添加数据报错
文章浏览阅读1.8k次。监听编辑板块切换开发工具:IntellJ Idea 开发语言:Kotlin功能描述:实现监听编辑板块切换效果图: 打印日志: 下面是实现该功能的代码: com.your.company.unique.plugin.id Djy 1.0
文章浏览阅读418次。MAC下配置SSH免密登录及相关报错_mac ssh-rsa
文章浏览阅读779次,点赞22次,收藏8次。S-N-K法全称Newman-Keuls或Student-Newman-Keuls法,又称复极差检验法或q检验法。最小显著极差的计算与Tukey法相同,只是将第一自由度换成了秩次距m,即计算。是指当平均数由大到小排序后,相比较的两个平均数之间(含这两个平均数)包含的平均数个数。1、利用数据分析工具获取方差分析结果:步骤参照。其中,m为秩次距,df为误差项自由度,2.1计算需要用到的最小显著极差LSR。2、利用公式进行多重比较。2.2平均数间的多重比较。参考资料:生物统计学。_snk检验 excel
文章浏览阅读3k次,点赞4次,收藏19次。在一个仓库中可以存放A和B两种产品,要求: 1)每次只能存入一种–互斥访问 2)A产品数量 - B产品数量 < M 3)B产品数量 - A产品数量 < N其中,M,N是正整数,使用PV操作描述A和B的入库过程。semaphore mutex = 1;int countA = 0,countB = 0;PA:while(1){ if(countA - countB < M -
文章浏览阅读541次。Shape of HDUTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7061 Accepted Submission(s): 3200Problem Description话说上回讲到海东集团推选老总的_hdu 2108 shape of hdu
文章浏览阅读133次。但是,智能照明在我国一直没有引起足够的重视,大部分建筑物采用的照明依然是传统的照明控制方式,因此,本文就智能照明系统在现代建筑中的应用进行分析, 继而使人们认识智能照明系统的优点,为其发展提供一些推动作用。智能化已经成为全球建筑发展的主流技术,其涵盖多个方面。在现代建筑中, 智能照明系统的设备不但多而且比较分散,待实现的控制功能较多,因而如何构建经济 合理、实用的智能照明系统,如何确定智能照明系统在现代建筑照明中的控制策略 是亟待解决的问题,只有把这些问题解决了,智能照明系统才能够在现代建筑中广泛的应用。
文章浏览阅读683次。基于CMake的构建系统(buildsystem),其组织形式是一组高级逻辑目标(high-level logical targets)。每个目标(target)对应于一个可执行文件或库,或者一个包含自定义命令的自定义目标。构建系统说明了目标之间的依赖关系,从而确定构建顺序和响应更改时的重生成规则。_install_interface
文章浏览阅读788次,点赞9次,收藏28次。先使用命令/usr/local/nginx/sbin/nginx -V 查看已安装的 Nginx 是否包HTTP_STUB_STATUS 模块,cat /opt/nginx-1.12.0/auto/options | grep YES #查看nginx已安装的所有模块。在Linux平台.上,在进行高并发TCP连接处理时,最高的并发数量都要受到系统对用户单一进程同时可打开文件数量的限制(这是因为系统为每个TCP连接都要创建一个socket句柄,每个socket句柄同时也是一个文件句柄)。
文章浏览阅读2.7w次,点赞211次,收藏852次。某高校欲开发一个成绩管理系统,记录并管理所有选修课程的学生的平时成绩和考试成绩,其主要功能描述如下: 1. 每门课程都有3到6个单元构成,每个单元结束后会进行一次测试,其成绩作为这门课程的平时成绩。课程结束后进行期末考试,其成绩作为这门课程的考试成绩。 2. 学生的平时成绩和考试成绩均由每门课程的主讲教师上传给成绩管理系统。 3. 在记录学生成绩之前,系统需要验证这些成绩是否有效。首先..._招聘考试成绩管理数据流程图
文章浏览阅读1.9k次。算术操作符:无论是在sqlserver,或者是java中,每种语言它都有算术操作符,大同小异。Oracle中算术操作符(+)(-)(*)(/)值得注意的是:/在oracle中就相当于显示中的除法5/2= 2.5比较操作符:其中等号可以换成其他运算符:(后面为该操作符的单条件查询样例)!=不等于selectempno,ename,jobfromscott.empwherejob!..._oracl除后剩余数