文件读写 哪个高手请教下文件的读写具体怎么操作的?怎么打开一个文件? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 流处理,java.IO包的类;一般用BufferredReader和BufferredWriter进行读。使用多线程会麻烦些 File f = new File("D:\\a.txt");BufferedReader bf = new Bufferedreader(new FileReader(f));然后就用bf.readLine。。等等方法去读.. http://bbxyhaihua.javaeye.com/blog/540975以后先自己搜搜! 读文件 文件名你自己换一个存在的public class TestRead { public static void main(String[] args) throws Exception{ FileInputStream fis = new FileInputStream("c:\\abc.txt"); byte[] b = new byte[1024]; int temp = 0; String result = ""; while(true){ temp = fis.read(b); if(temp==-1) break; result = result + new String(b,0,temp); } fis.close(); System.out.println(result); }}写文件import java.io.FileOutputStream;public class TestWrite { public static void main(String[] args) throws Exception{ FileOutputStream fos = new FileOutputStream("c:\\dd.txt"); String temp = "iou"; fos.write(temp.getBytes()); fos.close(); }简单的文件拷贝 同样是文件名自己换 import java.io.FileInputStream;import java.io.FileOutputStream;public class TestCopy { public static void main(String[] args) throws Exception{ FileInputStream fis = new FileInputStream("c:\\abc.txt"); FileOutputStream fos = new FileOutputStream("c:\\dd.txt"); byte[] b = new byte[1024]; int temp = 0; while(true){ temp = fis.read(b); if(temp==-1) break; fos.write(b,0,temp); } fis.close(); fos.close(); }} 接口:InputStream:读OutputStream:写适合二进制/文本文件的读写实现类:FileInputStream/ByteArrayInputStreamReader/Wriite适合文本文件的读写BufferedReader/FileRearer/FileWriter 方法很多呀。主要是java.io包中的类。 <select></select>标签问题 JSP页面输出问题 新手求救,子框架中刷新的方法 java替换字符问题 大家能不能推荐一下java生成缩略图比较好的库 高手们 IBATIS 的 多表查询 一个关于临时表的问题,临时表数据引用不到 关于时间类型的问题 如何制作定时执行的程序? 如何在jbuilder7中部署EJB的所有服务 对于spring2.5 需要控制数据打开与关闭连接吗? DOM4J 解析xml的问题
一般用BufferredReader和BufferredWriter进行读。使用多线程会麻烦些
BufferedReader bf = new Bufferedreader(new FileReader(f));
然后就用bf.readLine。。等等方法去读..
以后先自己搜搜!
public static void main(String[] args)
throws Exception{
FileInputStream fis = new
FileInputStream("c:\\abc.txt");
byte[] b = new byte[1024];
int temp = 0;
String result = "";
while(true){
temp = fis.read(b);
if(temp==-1) break;
result = result +
new String(b,0,temp);
}
fis.close();
System.out.println(result);
}
}写文件import java.io.FileOutputStream;
public class TestWrite {
public static void main(String[] args)
throws Exception{
FileOutputStream fos = new
FileOutputStream("c:\\dd.txt");
String temp = "iou";
fos.write(temp.getBytes());
fos.close();
}
简单的文件拷贝 同样是文件名自己换 import java.io.FileInputStream;
import java.io.FileOutputStream;public class TestCopy { public static void main(String[] args)
throws Exception{
FileInputStream fis = new
FileInputStream("c:\\abc.txt");
FileOutputStream fos = new
FileOutputStream("c:\\dd.txt");
byte[] b = new byte[1024];
int temp = 0;
while(true){
temp = fis.read(b);
if(temp==-1) break;
fos.write(b,0,temp);
}
fis.close();
fos.close();
}}
InputStream:读
OutputStream:写
适合二进制/文本文件的读写
实现类:FileInputStream/ByteArrayInputStreamReader/Wriite
适合文本文件的读写
BufferedReader/FileRearer/FileWriter