读文件:
String encoding = "gbk";
File file = new File("F:\\xxx.txt");
if (file.isFile() && file.exists()) { // 判断文件是否存在
InputStreamReader read = new InputStreamReader(
new FileInputStream(file), encoding);// 考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
list = new ArrayList
while ((lineTxt = bufferedReader.readLine()) != null) {
System.out.println(lineTxt);
if (lineTxt != "") {
list.add(lineTxt);
}
}
read.close();
}
写文件:
File outFile = new File(parentFile, inFile.getName() + outFileIndex
+ SUFFIX);
FileOutputStream out = new FileOutputStream(outFile);
inEndIndex += size;
inEndIndex = (inEndIndex < fileLength) ? inEndIndex : fileLength;
// 从输入流中读取字节存储到输出流中
OutputStreamWriter write = new OutputStreamWriter(out, "gbk");
BufferedWriter writer = new BufferedWriter(write);
int i = 0;
for (; inBeginIndex < inEndIndex; inBeginIndex++) {
writer.write(reader.read());
if ( (inBeginIndex+1) % 150 == 0 && i<8) {
if (index >= sizeurl) {
index = 0;
}
writer.write(urllist.get(index));
i++;
index++;
}
}
最好是用数据库存储,相对来说安全方便,
通过IO操作txt文件,最好学学用数据库