package com.Lab04;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
@SuppressWarnings("all")
public class Lab04 {
public static void main(String[] args) {
String filePath = "E:\\Lab04Test\\Lab04Test.txt";
String str = null;
String read = new Lab04().read("Write your word:");
byte[] bytes = new byte[1024];
int readLan;
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(filePath);
try {
while ((readLan = fileInputStream.read(bytes)) != -1){
str = new String(bytes,0,readLan);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
assert str != null;
String[] sentence = str.split("\\.");
System.out.println("The sentence contains your word is:");
for (int i = 0;i<sentence.length;i++){
if (sentence[i].contains(read)){
System.out.println(sentence[i] +".");
}
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} finally {
if (fileInputStream != null){
try {
fileInputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
public String read(String s){
System.out.print(s);
Scanner in = new Scanner(System.in);
return in.nextLine();
}
}
22320122_LinHai_Lab04.zip
需积分: 5 138 浏览量
2022-11-08
09:53:41
上传
评论
收藏 7KB ZIP 举报
扉页.
- 粉丝: 0
- 资源: 1
最新资源
- 基于ARM的指令调度和延迟分支
- 基于Vue和TypeScript的极简聊天应用设计源码 - HasChat
- 基于Vue2全家桶和Zcool数据的图片收集网站设计源码 - cool-picture
- 基于C和C++的二维绘制工具设计源码 - DrawPro
- Object.defineProperty 的 IE 补丁object-defineproperty-ie-master.zip
- 整卷预览.mhtml
- MySQL是一种广泛使用的开源关系型数据库管理系统,它提供了丰富的SQL语句用于数据库的创建、查询、更新和管理 以下是一些常见的
- MySQL是一种广泛使用的开源关系型数据库管理系统,它提供了丰富的SQL语句用于数据库的创建、查询、更新和管理 以下是一些常见
- MySQL是一种广泛使用的开源关系型数据库管理系统,它提供了丰富的SQL语句用于数据库的创建、查询、更新和管理 以下是一些常见的
- 基于Javascript的结婚请帖设计源码 - Invitation
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈