import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class BufferedInputOutputStreamExample
{
public static void main(String[] args) {
try{
BufferedInputStreamExample bisx=new BufferedInputStreamExample();
BufferedInputStream bis=bisx.inputMethod();
BufferedOutputStreamExample bosx=new BufferedOutputStreamExample();
bosx.outputMethod(bis);
}
catch(FileNotFoundException fnf)
{
System.out.println("Sorry--------File not exists");
}
catch(IOException io)
{
System.out.println("IOException ---:"+io.getMessage());
}
}
}
class BufferedInputStreamExample
{
BufferedInputStream bis=null;
BufferedInputStream inputMethod()throws FileNotFoundException,IOException
{
FileInputStream fin=new FileInputStream("C:/e-SDK-4.1-win32-x86_64 (1)/RahulExample/src/Test.java");
bis=new BufferedInputStream(fin);
int c;
while((c=bis.read())!=-1)
System.out.print((char)c);
System.out.println();
return bis;
}
}
class BufferedOutputStreamExample
{
BufferedOutputStream bos=null;
int outputMethod(BufferedInputStream bis)throws IOException,FileNotFoundException
{
bos=new BufferedOutputStream(new FileOutputStream("C:/varun.txt"));
int c;
while((c=bis.read())!=-1){
bos.write(c);
}
bis.close();
bos.close();
System.out.println("File created.............");
return 1;
}
}
在這個計劃中,我們使用的BufferedInputStream,當我想用的BufferedOutputStream,其創建文件中寫入Test.java文件中varun.txt文件中的內容,但不寫在VARUN任何東西從文件中讀取內容
.txt。如果我們將Test.java中的內容寫入varun.txt而不讀取它,則創建文件並寫入兩者。爲什麼這樣做就是這樣做的。在BufferedInputStream和BufferedOutputStream類中,爲什麼在寫入之前,讀取不好.......?
plz給答案。 –