Need interruption in my program flow
I am calling three classes from mymain method jButton4CreateMfActionPerformed. In myCheckDriverFile class, I am checking a file and if any errors are found, the errors are getting displayed and before I rectify those errors, the program is going toLogsDirectory class.
But what I need is, when I encounter errors inCheckDriverFile class, after I rectify those errors only the program should go toLogsDirectory class.
Can someone please help me with this.
Code for main class
privatevoid jButton4CreateMfActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
File sgm=new File(jTextField1FilenameBoxText);
File RootDir=new File(sgm.getParent());
CreateMNF cm=new CreateMNF();
cm.fileMNF(RootDir, jTextField1FilenameBoxText);
CheckDriverFile cdf=new CheckDriverFile();
cdf.CheckFile(RootDir, jTextField1FilenameBoxText);
LogsDirectory ld=new LogsDirectory();
ld.CheckFilenames(RootDir);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
Code for CheckDriverFile class
void CheckFile(File RootDir, String file)throws IOException
{
String[] lists=RootDir.list();
File DriverFile=new File(file);
int val;
char ch;
File inputfile=new File(file);
File inputfileTmp=File.createTempFile(inputfile.getName(),"tmp");
BufferedReader br=null;
BufferedWriter bw=null;
String line;
try
{
br=new BufferedReader(new FileReader(inputfile));
bw=new BufferedWriter(new FileWriter(inputfileTmp));
LineNumberReader lineRead=new LineNumberReader(br);
while((line=lineRead.readLine())!=null)
{
if((line.contains(".tif\" NDATA "))&&(!line.endsWith("TIFF>")))
{
int lineno;
lineno=lineRead.getLineNumber();
javax.swing.JOptionPane.showMessageDialog(null,"Line_"+lineno+"NDATA should be TIFF");
}
bw.write(line);
bw.newLine();
}
}
catch(NullPointerException n)
{
System.out.println(n.getMessage());
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
finally
{
try
{
br.close();
}
catch(Exception e)
{
}
try
{
bw.close();
}
catch(Exception e)
{
}
}
if(inputfile.delete())
inputfileTmp.renameTo(inputfile);
}
[4558 byte] By [
Simmya] at [2007-11-26 19:24:01]

Hi,
Instead of void CheckFile
have boolean CheckFile
so that it returns true if there are no errors. Then within jButton4CreateMfActionPerformed
method you could have if(cdf.checkFile()){
LogsDirectory ld=new LogsDirectory();
ld.CheckFilenames(RootDir);
}
HTH,
Chris
Could you please tell if I am right in understanding what you said for me to do?
Code for main class
private void jButton4CreateMfActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
File sgm=new File(jTextField1FilenameBoxText);
File RootDir=new File(sgm.getParent());
CreateMNF cm=new CreateMNF();
cm.fileMNF(RootDir, jTextField1FilenameBoxText);
CheckDriverFile cdf=new CheckDriverFile();
cdf.CheckFile(RootDir, jTextField1FilenameBoxText);
if(cdf.checkFile())
{
LogsDirectory ld=new LogsDirectory();
ld.CheckFilenames(RootDir);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
Code for CheckDriverFile class
boolean CheckFile(File RootDir, String file) throws IOException
{
String[] lists=RootDir.list();
File DriverFile=new File(file);
int val;
char ch;
File inputfile=new File(file);
File inputfileTmp=File.createTempFile(inputfile.getName(),"tmp");
BufferedReader br=null;
BufferedWriter bw=null;
String line;
try
{
br=new BufferedReader(new FileReader(inputfile));
bw=new BufferedWriter(new FileWriter(inputfileTmp));
LineNumberReader lineRead=new LineNumberReader(br);
while((line=lineRead.readLine())!=null)
{
if((line.contains(".tif\" NDATA "))&&(!line.endsWith("TIFF>")))
{
int lineno;
lineno=lineRead.getLineNumber();
javax.swing.JOptionPane.showMessageDialog(null, "Line_"+lineno+"NDATA should be TIFF");
}
bw.write(line);
bw.newLine();
}
}
catch(NullPointerException n)
{
System.out.println(n.getMessage());
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
finally
{
try
{
br.close();
}
catch(Exception e)
{
}
try
{
bw.close();
}
catch(Exception e)
{
}
}
if(inputfile.delete())
inputfileTmp.renameTo(inputfile);
return false;
}
Message was edited by:
Simmy
Almost there.
I used checkFile() as an example. For your code you would need to replace cdf.CheckFile(RootDir, jTextField1FilenameBoxText);
with if(cdf.CheckFile(RootDir, jTextField1FilenameBoxText)){
LogsDirectory ld=new LogsDirectory();
Id.CheckFilenames(RootDir);
}
It's also a good idea to remember naming conventions with your classes and methods. Each word in a class name should begin with a capital letter (e.g. ThisIsMyClass) and your method name should begin with a lower case letter then subsequent capital letters for additional words (e.g. thisIsMyMethod).
HTH,
Chris
I think I am wrong in my returning statement return false; in the class CheckDriverFile, because the necessary process is not happening. Please help me.
Code for main class
private void jButton4CreateMfActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
File sgm=new File(jTextField1FilenameBoxText);
File RootDir=new File(sgm.getParent());
CreateMNF cm=new CreateMNF();
cm.fileMNF(RootDir, jTextField1FilenameBoxText);
CheckDriverFile cdf=new CheckDriverFile();
if(cdf.CheckFile(RootDir, jTextField1FilenameBoxText))
{
LogsDirectory ld=new LogsDirectory();
ld.CheckFilenames(RootDir);
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
Code for CheckDriverFile class
boolean CheckFile(File RootDir, String file) throws IOException
{
String[] lists=RootDir.list();
File DriverFile=new File(file);
int val;
char ch;
File inputfile=new File(file);
File inputfileTmp=File.createTempFile(inputfile.getName(),"tmp");
BufferedReader br=null;
BufferedWriter bw=null;
String line;
try
{
br=new BufferedReader(new FileReader(inputfile));
bw=new BufferedWriter(new FileWriter(inputfileTmp));
LineNumberReader lineRead=new LineNumberReader(br);
while((line=lineRead.readLine())!=null)
{
if((line.contains(".tif\" NDATA "))&&(!line.endsWith("TIFF>")))
{
int lineno;
lineno=lineRead.getLineNumber();
javax.swing.JOptionPane.showMessageDialog(null, "Line_"+lineno+"NDATA should be TIFF");
}
bw.write(line);
bw.newLine();
}
}
catch(NullPointerException n)
{
System.out.println(n.getMessage());
}
catch(IOException e)
{
System.out.println(e.getMessage());
}
finally
{
try
{
br.close();
}
catch(Exception e)
{
}
try
{
bw.close();
}
catch(Exception e)
{
}
}
if(inputfile.delete())
inputfileTmp.renameTo(inputfile);
return false;
}
I thought the whole idea of CheckFile was to discover and repair any errors in the file. Once you have done that return true. This will then enable the program to go into the body of the boolean if loop where you create your logs directory.
Please tell me where to rectify in my code.
Please tell me where to give return true in my CheckDriverFile class, once I rectify my errors found.
It looks to me that you are returning false once all of the checks have been done. Replace false with true.
In both my classes, if errors are there, it should get displayed one after the other and not errors from both the classes together. That is after I rectify errors from CheckDriverFile class, then only the errors from the class LogsDirectory should get displayed.
If I return true, if errors are there in both the classes, both are getting displayed
I really don't understand what you are trying to do. It appeared to me that if you encountered errors in your CheckDriverFile class then you wanted to print them out and then rectify them. Once that was completed you then wanted to call the LogsDirectory method structure. That is what now happens.
I really don't understand what you are trying to do. It appeared to me that if you encountered errors in your CheckDriverFile class then you wanted to print them out and then rectify them. Once that was completed you then wanted to call the LogsDirectory method structure. That is what now happens.
Your understanding is absolutely fine. If errors are there in both CheckDriverFile class and LogsDirectory class, then the errors of CheckDriverFile class only should get displayed and once I rectify those errors, then the errors of the LogsDirectory class should get displayed.
But now if errors are there in both CheckDriverFile class and LogsDirectory class, the errors of both are getting displayed one after the other and not waiting for me to first rectify the errors of CheckDriverFile class
Please do tell me if I need to modify anything in my below code and should I return true immediately after this condition
if((line.contains(".tif\" NDATA "))&&(!line.endsWith("TIFF>")))
{
int lineno;
lineno=lineRead.getLineNumber();
javax.swing.JOptionPane.showMessageDialog(null, "Line_"+lineno+"NDATA should be TIFF");
}
Where are you fixing the errors? On looking closer it seems that you are identifying the errors then not fixing them. Only when you have fixed them should you return true.
Once the errors get displayed, I open the file in UltraEdit and manually fix them and save it. Only after I do this process, the program flow should go to LogsDirectory class.Message was edited by: Simmy
Hi,Sorry about the delay in replying. I'm not 100% au fait with UltraEdit but I do find it odd that you are manually updating the files. Why not let the program do it for you?
Manual updation in UltrEdit is the expected output. So please tell me how do I display the errors of the second class only after rectifying the errors of my first class. Please help me with this.
Simmya at 2007-7-21 17:34:38 >
