java小说在线阅读代码 小说阅读器java代码
java问题 我用流读取一个txt小说,把小说的内容放进一个集合里, 代码怎么写?
public static void main(String[] args) {
创新互联公司-专业网站定制、快速模板网站建设、高性价比吉隆网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式吉隆网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖吉隆地区。费用合理售后完善,10余年实体公司更值得信赖。
try{
File file = new File("E:\\a.txt");//创建文件对象
BufferedReader br = new BufferedReader(new FileReader(file)); //创建读取流
//读取数据
String temp = br.readLine();
String line;
while((line = br.readLine()) != null){
temp += "," + line;
}
if(temp == null){
System.out.println();
}else{
//分割字符串
String []str = temp.split(",");
//创建double数组并赋值
Double[] d = new Double[str.length];
for(int i = 0 ;i str.length ;i++){
d[i] = Double.parseDouble(str[i]);
}
//打印double数组
for(int i = 0 ; i d.length ; i++){
System.out.println(d[i]);
}
}
}catch(Exception e){
}
java 怎么提取 txt小说里面的章节目录 并记录位置
以下是一些基本的功能代码,读取TXT部分代码来源于网络:
public static void readTxtFile(String filePath) {
try {
String encoding = "UTF-8";
File file = new File(filePath);
if (file.isFile() file.exists()) { // 判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);// 考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
int offset = 0; //章节所在行数
int count = 1; //章节数
ListInfoVo list = new ArrayListInfoVo();
InfoVo infoVo;
while ((lineTxt = bufferedReader.readLine()) != null) {
infoVo = new InfoVo();
offset++;
if (lineTxt.contains("第") lineTxt.contains("章")) {
infoVo.setCount(count);
infoVo.setOffset(offset);
infoVo.setTitle(lineTxt);
list.add(infoVo);
count++;
}
}
System.out.println(list.size());
System.out.println(list.get(0).getCount());
System.out.println(list.get(0).getOffset());
System.out.println(list.get(0).getTitle());
read.close();
} else {
System.out.println("找不到指定的文件");
}
} catch (Exception e) {
System.out.println("读取文件内容出错");
e.printStackTrace();
}
}
public static void main(String[] args) {
// Console.mainMenu();
String filePath = "C:\\20130815.txt";
readTxtFile(filePath);
}
InfoVo结构:
public class InfoVo {
private Integer count;
private Integer offset;
private String title;
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public Integer getOffset() {
return offset;
}
public void setOffset(Integer offset) {
this.offset = offset;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
java语言框架编写小说阅读器代码
int option = -1;
Object options[] = { "Yes", "No" };
option = JOptionPane.showOptionDialog(frame, "是否退出阅读?", "exit",
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
options, options[0]);
switch (option) {
case JOptionPane.YES_OPTION:
System.exit(0);
}
}
怎么用JAVA做个RSS阅读器 求代码
解析XML 希望对你有帮助
public class ParseXML {
//下载一个XML
public void downloadXMLFile(String url,String dir) throws IOException{
//下载的文件夹创建
File ff = new File(dir);
if(!ff.exists()){
ff.mkdir();
}
//爬取指定url下的内容
URL u = new URL(url);
URLConnection uc = u.openConnection();
InputStream is = uc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
//d:xml
FileWriter fw = new FileWriter(dir+File.separator+getFileNameByURL(url));
BufferedWriter bw = new BufferedWriter(fw);
String line;
while((line=br.readLine())!=null){
bw.write(line);
bw.newLine();
}
bw.close();
br.close();
is.close();
fw.close();
}
//解析xml
public ListNews parseXML(File file) throws DocumentException{
//创建解析器
SAXReader sr = new SAXReader();
//要解析的文件
Document doc = sr.read(file);
//获得跟节点
Element e = doc.getRootElement();
System.out.println(e.getName());
ListNews list = new ArrayListNews();
//从跟节点下查找某节点
ListElement listTitle = e.selectNodes(Common.title);
ListElement listLink = e.selectNodes(Common.link);
ListElement listDesc = e.selectNodes(Common.desc);
ListElement listPub = e.selectNodes(Common.pubDate);
for(int i=0;ilistTitle.size();i++){
News news = new News();
news.setNTITLE(listTitle.get(i).getText());
news.setNLINK(listLink.get(i).getText());
news.setNDESC(listDesc.get(i).getText());
news.setNPUBDATE(listPub.get(i).getText());
System.out.println(listTitle.get(i).getText());
System.out.println(listLink.get(i).getText());
list.add(news);
}
return list;
}
//获取文件名
public String getFileNameByURL(String url){
String[] names = url.split("/");
return names[names.length-1];
}
public static void main(String[] args){
ParseXML px = new ParseXML();
try {
px.downloadXMLFile("", "f://xml");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
File f = new File("f://xml//rss_newstop.xml");//XML
try {
ListNews list = px.parseXML(f);
NewsServiceImple nsi = new NewsServiceImple();
nsi.insertNews(list, f.getName());
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
本文名称:java小说在线阅读代码 小说阅读器java代码
标题路径:http://cdiso.cn/article/hgihgo.html