当前位置:网站首页>mocklog_模拟日志
mocklog_模拟日志
2022-06-21 17:35:00 【算法朝圣者】
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class mock {
/*
* flieName:文件名
* num_Row:输入多少条数据
* content:每条/每行数据的内容
* */
public static void mock2Txt(String flieName, int num_Row, String[] content) {
File file = new File(flieName);
FileWriter fW = null;
BufferedWriter bw = null;
Random random = new Random();
try {
fW = new FileWriter(file, true);
bw = new BufferedWriter(fW);
for (int i = 0; i <= num_Row; i++) {
String cont= content[random.nextInt(content.length)];
bw.write(cont);
bw.newLine();
System.out.println("第" + i + "次输入:" + content);
}
bw.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fW != null) {
try {
fW.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
/*
* flieName:文件名
* */
public static synchronized ArrayList<String> readTxt2ArrayList(String flieName) throws IOException {
InputStreamReader isr = new InputStreamReader(new FileInputStream(flieName), "UTF-8");
BufferedReader br = new BufferedReader(isr);
ArrayList<String> arrylist = new ArrayList<String>();
String line = null;
int count = 0;
//=====================================================
while ((line = br.readLine()) != null) {
if (!line.equals("0")) {//文本结束的标志
if (!line.equals("")) {//不需要读取空行
arrylist.add(line);
}
}
count++;
}
//=====================================================
br.close();
isr.close();
if (line !=null) {//清空变量值
line=null;
count=0;
}
System.out.println("第"+count+"行结果为:"+line);
System.out.println(arrylist.toArray().length);
//=====================================================
return arrylist;
}
public static void main(String[] args) {
}
}
边栏推荐
- Dao and encapsulation of entity classes
- ACL 2022 | 基于自监督图对齐的多语言知识图谱推理
- 从“村办企业”到“百亿集团”,红星实业何以完成“蝶变”?
- 协同过滤(Collaborative Filtering)
- 秒云云原生信创全兼容解决方案再升级,助力信创产业加速落地
- El expression
- Listener and filter (monitor and interceptor) in Servlet
- el-table分页全选功能讲解
- Generics of typescript
- Canvas interactive color gradient JS special effect code
猜你喜欢
随机推荐
GoF模式-03-行为型模式(下)
How to apply for SSL certificate using IP
宏基因组 (个人笔记)
启动!阿里巴巴编程之夏2022
Ant group's self-developed tee technology has passed the national financial technology product certification, and 47 tests have met the requirements
Start! Alibaba programming summer 2022
Canvas球体粒子变幻颜色js特效
The best network packet capturing tool mitmproxy
Servlet中Listener与Filter (监视器与拦截器)
GOF mode-03-behavioral mode (bottom)
2021-10-26 metagenome analysis (personal note 2)
Canvas interactive color gradient JS special effect code
删除指定的screen
Guys, please ask me a question about flynk SQL. I have an FQL statement, insert into C sale
What is an SSL certificate and what are the benefits of having an SSL certificate?
JDBC 笔记
老师们,oracle-cdc遇到不能解析的dml语句,因为这个语句里面有个字段是比较特殊的空间地理位
Stata quick check backup (personal notes)
Canvas dynamic mesh background JS effect
互联网通信流程









