❶ java 寫入txt
10001?不是1001?
1001 - 100500 這樣500個文件。
是一個文件里寫500個數,還是一個文件里寫一個數?
下邊是一個文件里寫一個數字的做法。
import java.io.File;
import java.io.FileWriter;
public class Test {
public static void main(String[] args) {
File root = new File("D:\\result");
root.mkdirs();
FileWriter fw = null;
for (int i = 1; i <= 500; i++) {
try {
fw = new FileWriter(new File(root, "100" + i + ".txt"));
fw.write("" + i);
} catch (Exception e) {
} finally {
try {
fw.close();
} catch (Exception e) {
}
}
}
}
}
❷ java程序要處理一本txt格式的小說,可是裡面的章節是亂的。如何對小說章節重新排序
讀取TXT,將每一章轉成一個對象,放到list,然後自定義排序規則,排好序後再轉成TXT;
❸ java 怎麼提取 txt小說裡面的章節目錄 並記錄位置
簡單說, 就是使用正則表達式匹配,
第1章aa
xxxxx
第2章bb
xxxx
第3章cc
xxxxx
BufferReader的readLine() ,可以一行一行的讀取數據, 如果發現某一行滿足 第X章 這種樣式的, 就認為這是章節的開頭, 就記錄下該行的位置.....
假設第2章在36行, 顯示的時候每20行1頁,
那麼第2章的位置,就在第二頁的16行. (36%20=16 36除20的余數16..)
❹ 如何在Java中打開TXT文件
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.IOException;
publicclassReadText{
publicstaticvoidmain(String[]args)
{
readTextContent();
}
()
{
try
{
Filefile=newFile("E://test.txt");
FileInputStreamfis=newFileInputStream(file);
Stringstr="";
byte[]bytes=newbyte[1024];
intlength=0;
while((length=fis.read(bytes))!=-1)
{
str+=newString(bytes,0,length);
}
System.out.println(str);
}catch(FileNotFoundExceptione)
{
e.printStackTrace();
}catch(IOExceptione)
{
e.printStackTrace();
}
}
}
❺ java問題 我用流讀取一個txt小說,把小說的內容放進一個集合里, 代碼怎麼寫
public static void main(String[] args) {
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文件
給你我寫的兩個方法!!作為參考吧!
/**
* @author CaoShun
* @see 從指定位置文件中一行一行讀取內容並把每行存入List集合
* */
public static List readInputByRow(String path) {
List list=new ArrayList();
File file=new File(path);
try {
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader reader = new BufferedReader(isr);
String tempstring="";
while((tempstring=reader.readLine())!=null)
{
list.add(tempstring);
//System.out.println("debug in ReadWriteOEMInfo.java on line 99 tempstring : "+tempstring);
}
reader.close();
isr.close();
fis.close();
return list;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
/**
* @author CaoShun
* @see 從指定位置文件中,讀指定一行數據
* */
public static String readInputByRow(String path,int num) {
File file=new File(path);
try {
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader reader = new BufferedReader(isr);
String tempstring="";
int line=1;
while((tempstring=reader.readLine())!=null)
{
if(line==num){
break;
}
line++;
}
reader.close();
isr.close();
fis.close();
return tempstring;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
❼ java的txt文檔與java
默認打開方式為文本編輯器,它的樣式就成了上面的~~這有什麼好奇怪的
❽ java 寫txt文件
import java.io.*;
public class Test {
public static void main(String[] args){
String s = new String();
String s1 = new String();
try {
File f = new File("E:\\123.txt");
if(f.exists()){
System.out.print("文件存在");
}else{
System.out.print("文件不存在");
f.createNewFile();//不存在則創建
}
BufferedReader input = new BufferedReader(new FileReader(f));
while((s = input.readLine())!=null){
s1 += s+"\n";
}
System.out.println(s1);
input.close();
s1 += "添加的內容!";
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
❾ 在哪個網站可以下載JAVA格式的小說
www.bookdown.com
你點擊JAR小說下載,就可以了。而且這個網站上也有電子書製作軟體,如果你遇到了你喜歡的電子書,網上,或者你自己找到的網站上下載下來的電子書非常喜歡,想做成JAR格式的,也可以用這個網站上的電子書轉換軟體,自己經過簡單的幾步就可以轉換完成了。
❿ java txt電子書軟體哪個好
JAVA方便的多``````如果是TXT的```就適用於所有Motorola支持JSR75的手機(包括V3i, L7等)!軟體已取得授權。直接用MIDway下載安裝即可。無需修改手機文件即可使用(如果已經修改過還請改回或重新刷機)!不用回答任何詢問!
閱讀存儲卡上的文本文件或圖片文件。文本文件大小不受限制!閱讀再大的文件也能運行如飛。文件格式不受限制,可以是ANSI,unicode, big endian unicode, UTF8格式中任一種。(因為覆蓋繁體字的字型檔太大,請勿選擇ANSI格式)
對於不支持插卡的手機如L6,依然保持了數據線下載的功能。下載的文件大小隻受存儲空間限制,也就是說可以下載數百K大小的txt文件。
翻頁速度超快!按下翻頁鍵瞬間完成翻頁。
支持書簽功能。各圖書有各自獨立的書簽。書簽數量不受限制。書簽設置和讀取操作直觀方便。
支持向前向後快速翻頁功能。只需按住2/上或8/下鍵即可進入快速翻頁。按的時間越長翻頁速度越快。
快速切換到前一或後一文件。將動漫圖片序列放在同一目錄下即可瀏覽動漫。
自動翻頁功能!翻頁速度可為3-99秒。
平滑滾屏功能!滾屏速度分4級。
字元串搜索功能!可以從文件頭或當前頁開始搜索。搜索到的字元串將反色顯示。
狀態條指示當前閱讀圖書的狀態。
密碼保護功能和快速退出功能。閱讀圖書時按*鍵或合上翻蓋即進入密碼保護界面。在密碼保護界面按*鍵即快速退出。最大限度保護你的隱私。
顏色設置功能。可以按紅綠藍三原色
下載地址
http://www.motobbs.com/viewthread.php?tid=85460&extra=page%3D1