java小說在線閱讀代碼 小說閱讀器java代碼

java問題 我用流讀取一個(gè)txt小說,把小說的內(nèi)容放進(jìn)一個(gè)集合里, 代碼怎么寫?

public static void main(String[] args) {

創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比吉隆網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式吉隆網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋吉隆地區(qū)。費(fèi)用合理售后完善,10余年實(shí)體公司更值得信賴。

try{

File file = new File("E:\\a.txt");//創(chuàng)建文件對(duì)象

BufferedReader br = new BufferedReader(new FileReader(file)); //創(chuàng)建讀取流

//讀取數(shù)據(jù)

String temp = br.readLine();

String line;

while((line = br.readLine()) != null){

temp += "," + line;

}

if(temp == null){

System.out.println();

}else{

//分割字符串

String []str = temp.split(",");

//創(chuàng)建double數(shù)組并賦值

Double[] d = new Double[str.length];

for(int i = 0 ;i str.length ;i++){

d[i] = Double.parseDouble(str[i]);

}

//打印double數(shù)組

for(int i = 0 ; i d.length ; i++){

System.out.println(d[i]);

}

}

}catch(Exception e){

}

java 怎么提取 txt小說里面的章節(jié)目錄 并記錄位置

以下是一些基本的功能代碼,讀取TXT部分代碼來源于網(wǎng)絡(luò):

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; //章節(jié)所在行數(shù)

int count = 1; //章節(jié)數(shù)

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("讀取文件內(nèi)容出錯(cuò)");

e.printStackTrace();

}

}

public static void main(String[] args) {

// Console.mainMenu();

String filePath = "C:\\20130815.txt";

readTxtFile(filePath);

}

InfoVo結(jié)構(gòu):

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做個(gè)RSS閱讀器 求代碼

解析XML 希望對(duì)你有幫助

public class ParseXML {

//下載一個(gè)XML

public void downloadXMLFile(String url,String dir) throws IOException{

//下載的文件夾創(chuàng)建

File ff = new File(dir);

if(!ff.exists()){

ff.mkdir();

}

//爬取指定url下的內(nèi)容

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{

//創(chuàng)建解析器

SAXReader sr = new SAXReader();

//要解析的文件

Document doc = sr.read(file);

//獲得跟節(jié)點(diǎn)

Element e = doc.getRootElement();

System.out.println(e.getName());

ListNews list = new ArrayListNews();

//從跟節(jié)點(diǎn)下查找某節(jié)點(diǎn)

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代碼
網(wǎng)頁地址:http://muchs.cn/article10/hgihgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、App開發(fā)、自適應(yīng)網(wǎng)站網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)