BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

waiting to read a file

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder Deployment
View previous topic :: View next topic  
Author Message
Owen
Guest





PostPosted: Wed Apr 21, 2004 8:24 pm    Post subject: waiting to read a file Reply with 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.


Back to top
pnichols
Guest





PostPosted: Tue Apr 27, 2004 5:34 am    Post subject: Re: waiting to read a file Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> JBuilder Deployment All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.