java生成txt檔案,讀txt檔案

2021-09-09 02:30:40 字數 1129 閱讀 2698

1.方法1

public

static

void

main(string args)

catch

(exception e)

system.out.println(">>>>>>>>>>>>>>>>>>write end");

try filereader.close();

} catch

(exception e)

system.out.println(">>>>>>>>>>>>>>>>>>read end");
}

2.方法2

public

static

void

main(string args)

catch

(filenotfoundexception e)

string ss = "cname\t\tccode\t\tcreatedate\n";

ss += "dbc券\t\t111188\t\t2017-05-14\n";

ss += "zc券\t\t111199\t\t2017-05-14\n";

//將字串轉成位元組陣列

byte b =ss.getbytes();

trycatch

(ioexception e1)

system.out.println("write end>>>>>>>>>>>");

//以下為讀檔案操作

inputstream in = null

;

trycatch

(filenotfoundexception e3)

//開闢乙個空間用於接收檔案讀進來的資料

byte b1 = new

byte[1024];

int i = 0;

trycatch

(ioexception e4)

//將byte陣列轉換為字串輸出

system.out.println(new string(b1, 0, i));

system.out.println("read end>>>>>>>>>>>");

}

txt檔案讀操作

名稱 product.txt 檔案內容 1 f 開啟檔案product.txt 2 f.readlins 讀出檔案的所有行,每一行乙個字串,例如 iphone 9929 n 3 lines 由每一行變成的字串組成的列表 4 line lines的元素,即上面的字串。5 列印的結果是字串中的內容,即 ...

PHP生成TXT檔案 php讀取txt檔案內容

filename filename.txt header content disposition attachment filename filename 輸出內容 直接用echo輸出,r n 用以換行。第一步 處理中文檔名 filename 中文檔名.txt encoded filename ur...

C 生成TXT檔案

要將資料結果儲存到txt文字,首先要建立乙個txt文字,有三種方法 string result1 f result1.txt 1.writer new streamwriter filename 2.writer file.createtext filename 3.filename stream ...