1.从文件中读取数据
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class main
{
public static void main(String[] args) throws IOException
{
//file read
FileReader fReader = new FileReader("data.txt");
BufferedReader brBufferedReader = new BufferedReader(fReader);
String line = "";
String[] tempString =null;
while ((line = brBufferedReader.readLine())!=null)
{
tempString = line.split(",");
System.out.println(tempString[0]+":"+tempString[1]+":"+tempString[2]);
}
}
}
2.数据写入文件
import java.io.FileWriter;
import java.io.IOException;
public class main
{
public static void main(String[] args) throws IOException
{
FileWriter fWriter= new FileWriter("test_da.txt");
fWriter.write("hello world"+"\n"+"helloworld");
fWriter.close();
}
}
3.文件的输出和输入经常要和路径搭配,效果会很好。<pre name="code" class="java">String pathString = System.getProperty("user.dir");
**文件夹的分隔符我在windos是用 "/"这个,linux上还没试过。