大家好!!新人求罩!
1 import java.io.File; 2 import java.io.FileInputStream; 3 import java.io.FileNotFoundException; 4 import java.io.IOException; 5 6 7 public class work6 { 8 9 /** 10 * @param args 11 * @throws IOException 12 */ 13 public static void main(String[] args) throws IOException { 14 // TODO Auto-generated method stub 15 File file = new File("C:\Users\wang\Desktop\io作业.txt");//文件的地址!!! 16 //System.out.println(file.exists()); 17 FileInputStream in = new FileInputStream(file); 18 19 byte[] b = new byte[1024]; 20 21 int c = 0; 22 23 String str = ""; 24 25 while((c = in.read(b)) != -1){ 26 str += new String(b,0,c);//在此拼接 27 } 28 String[] s = str.split(" ");//以 来截取!转化为数组! 29 for(int i = 0; i < s.length; i++){//遍历当前数组! 30 System.out.print((i+1)+" "+s[i]); 31 } 32 } 33 34 }
一个简单的读取就完成了!!就是这么简单!