package day20181122;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
public class ReadTxt {
private String fileName="stu.txt";
public ReadTxt(String fileName) {
this.fileName=fileName;
// System.out.println("cionstruct");
}
public void readFile()
{
try {
File file=new File(fileName);
InputStreamReader in;
in = new InputStreamReader(new FileInputStream(file),"utf-8");
BufferedReader br=new BufferedReader(in);
String line="";
line=br.readLine();
while(line!=null)
{
String[] data=line.split(";");
int len=data.length;
for(int i=0; i<len; i++)
System.out.println(data[i]+"-------");
System.out.println(line);
line=br.readLine();
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void writeTxt(String filed)
{
String writeFileName="src/day20181122/student.txt";
try {
File f=new File(writeFileName);
if(f.exists())
f.createNewFile();
BufferedWriter bw=new BufferedWriter(new FileWriter(f));
bw.write(filed);
bw.flush();
bw.close();
System.out.println("write file succeed");
}catch(Exception e) {
e.printStackTrace();
}
}
}