File Manipulation

Java來進行檔案的讀取
java.lang.String strFileName=args[0];
java.io.File objFile=new java.io.File(strFileName);;
java.io.FileReader objFileReader;
char[] chrBuffer = new char[10];
int intLength;

if(objFile.exists())
 { objFileReader = new java.io.FileReader(objFile);
 while((intLength=objFileReader.read(chrBuffer))!=-1){ out.write(chrBuffer,0,intLength); }
 objFileReader.close(); }
 out.println("File not existed: "+strFileName); }

String nameOfTextFile = "/usr/anil/imp.txt";
try
 { PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
 pw.println(str);
 pw.close(); }
catch(IOException e) { out.println(e.getMessage()); }

This page is powered by Blogger. Isn't yours?