java 读取string_Java从文件读取字符串,读到\n不会换行

[Java] 纯文本查看 复制代码package dao;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.util.ArrayList;

import java.util.HashSet;

import java.util.Random;

import domain.Question;

public class QuestionDao {

private ArrayList list = new ArrayList<>();

{

HashSet set = new HashSet<>();

BufferedReader reader = null;

try {

reader = new BufferedReader(new FileReader("src//dbfile//t123.txt"));

String value=reader.readLine();

while(value!=null) {

String[] v = value.split("#");

Question q = new Question(v[0],v[1]);

set.add(q);

value=reader.readLine();

}

list.addAll(set);

reader.close();

} catch (Exception e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

}

}

public ArrayList getQuestion(){

HashSet set = new HashSet<>();

while(set.size()!=5) {

Random r = new Random();

int index = r.nextInt(list.size());

set.add(list.get(index));

}

return new ArrayList(set);

}

}

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页