 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Owen Guest
|
Posted: Wed Apr 21, 2004 8:24 pm Post subject: waiting to read a file |
|
|
Hello:
I want to wait to read a file that other program can write, I don't want get
exception want a try to read and how can I do that.
Best Regards.
Owen.
|
|
| Back to top |
|
 |
pnichols Guest
|
Posted: Tue Apr 27, 2004 5:34 am Post subject: Re: waiting to read a file |
|
|
Owen wrote:
| Quote: | Hello:
I want to wait to read a file that other program can write, I don't want
get exception want a try to read and how can I do that.
Best Regards.
Owen.
|
Not sure I understand what you wish to do. Correct me if I am wrong, but you
want to read a file that another program wrote.
Simple to do..
Example:
package filereader;
import java.io.*;
public class ReadFile {
public ReadFile() {
}
private String ReadTheFile(String fileName) throws IOException{
File file= new File(fileName);
char fData[]= new char[(int)file.length()];
String sResult="";
try {
if (file.exists()) {
BufferedReader br = new BufferedReader(new FileReader(file));
while (br.read() != -1) {
br.read(fData);
}
sResult=new String(fData);
}
else
sResult="File "+fileName+ " was not found.";
}
catch(IOException ioex) {
System.out.println("tError reading file "+fileName);
}
return sResult;
}
public static void main (String args[]) {
ReadFile rf= new ReadFile();
String sData="";
try {
sData=rf.ReadTheFile("/home/paul2/somwfile.log");
}
catch (Exception ex) {
ex.printStackTrace();
}
System.out.println("t The Data contained in the file is: n");
System.out.println(sData);
System.out.println("ntEnd of File Data");
}
}
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|