package com.test1;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class ReadFileTest1 {
/**
* @param args
*/
public static void readFileBytes(String fileName){
File file=new File(fileName);
try {
FileInputStream in = new FileInputStream(file);
int tempbyte;
try {
while((tempbyte=in.read())!=-1){
System.out.write(tempbyte);
System.out.println(tempbyte);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
readFileBytes("D://workspace//Hello//src//com//test1//tt.txt");
}
}
=======================================================
从上面的那么多的代码大部分是自己生产的,主要的就几行代码:
package com.test1;
public class ReadFileTest1 {
public static void readFileBytes(String fileName){
File file=new File(fileName);
while((tempbyte=in.read())!=-1){
System.out.write(tempbyte);
System.out.println(tempbyte);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
readFileBytes("D://workspace//Hello//src//com//test1//tt.txt");
}
}
========================================================
package com.test1;
这个是我从一个朋友那里学到的,其实我也没看视频自己摸索前进。
就是建立一个包,名字取有意义的就成。