I/O求助
怎么利用I/O来读取文件,,,体现读取超时。。。求简单程序!!! --------------------编程问答-------------------- 读文件不会超时。 --------------------编程问答-------------------- 就是用io写个读取文件,要求体现出读取文件超时的作法 --------------------编程问答----------------------------------------编程问答-------------------- 作业请翻书... --------------------编程问答-------------------- public void Selectall() {
import java.io.*;
public class Test {
public static void main(String[] args) {
FileInputStream n = null;
StringBuffer s = new StringBuffer();
int temp = 0;
try{
n = new FileInputStream("f://a.txt");
while((temp = n.read()) != -1){
s.append((char)temp);
}
//这种方法效率会高一些。
/*byte b[] = new byte[1024];
while((temp=n.read(b))!=-1){
s.append(new String(b,0,temp));
}*/
System.out.print(s.toString());
}
catch(Exception e){
e.printStackTrace();
}
finally {
try{
n.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
//装没人的信息到数组中
String[] arr=null;
//把每个人的信息分开装到数组中
String[] every=null;
//装取出的字符
String s="";
int a=-1;
File f=new File("D:/contact.txt");
Reader in=null;
try {
in=new FileReader(f);
while((a=in.read())!=-1){
s+=(char)a;
}
} catch (Exception e) {
e.printStackTrace();
}
//每个人的信息装入数组中
arr=new String[s.length()];
arr=s.split("\r\n");
for(int i=0;i<arr.length;i++){
every=new String[arr[i].length()];
every=arr[i].split(" ");
for(int j=0;j<every.length;j++){
if(j==0){
System.out.print("联系人姓名:"+every[0]+" ");
}else if(j==1){
System.out.print("年龄:"+every[1]+" ");
}else if(j==2){
System.out.print("电话号码::"+every[2]+" ");
}else if(j==3){
System.out.print("地址:"+every[3]+" ");
}
}
System.out.println();
}
} --------------------编程问答-------------------- sleep --------------------编程问答-------------------- mark --------------------编程问答-------------------- 多长时间才算超时 --------------------编程问答-------------------- 会有超时吗 没接触过 --------------------编程问答-------------------- 楼主能解释下读取超时么?
补充:Java , Java SE