import java.io.*;
public class FileInputStreamTest {
public static void main(String[] args) throws IOException
{
//创建字节输入流
FileInputStream fis = new FileInputStream("FileInputStreamTest.java");
//创建一个长度为1024的“竹筒”
byte[] bbuf = new byte[1024];
//用于保存实际读取的字节数
int hasRead = 0;
//使用循环来重复“取水”过程
while ((hasRead = fis.read(bbuf)) > 0 )
{
//取出“竹筒”中水滴(字节),将字节数组转换成字符串输入!
System.out.print(new String(bbuf , 0 , hasRead ));
}
fis.close();
}
}
public class FileInputStreamTest {
public static void main(String[] args) throws IOException
{
//创建字节输入流
FileInputStream fis = new FileInputStream("FileInputStreamTest.java");
//创建一个长度为1024的“竹筒”
byte[] bbuf = new byte[1024];
//用于保存实际读取的字节数
int hasRead = 0;
//使用循环来重复“取水”过程
while ((hasRead = fis.read(bbuf)) > 0 )
{
//取出“竹筒”中水滴(字节),将字节数组转换成字符串输入!
System.out.print(new String(bbuf , 0 , hasRead ));
}
fis.close();
}
}
这才算是当前目录.
你看看你的project下有这个没有?不是src那个目录下的。
public class text {
public static void main(String[] args) {
FileInputStream fin=null;
FileOutputStream fout=null;
try {
fin=new FileInputStream("f:\\a.jpg");
fout=new FileOutputStream("e:\\a.jpg");
byte []bytes=new byte[512];
int n=0;
try {
while((n=fin.read(bytes))!=-1){
try {
fout.write(bytes,0,n);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
try {
fin.close();
fout.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}}
这是我的代码