Strange problem in java

Hi,

I have a following program , this program call aother classes .

my problem is that if I run loop to call the classe

for (int i =3;i<=4;i++), I get a strange error saying :

Classification accuracy = 100.0 %

error accuracy = 0.0 %

Accuracy = 100.0 %

Error rate = 0.0 %

java.io.FileNotFoundException: dataf\iris\TrainingData.txt (Access is denied)

But when I run for evry single iteration for example

for (int i =3;i<=3;i++),

There is no problem, I need 10 iteration for this code so, it is not cconvenient to everytime for every iteration I run the program again and chnage the loob for every single iteration to get correct results like this:

for (int i =1;i<=1;i++), :

run again

for (int i =2;i<=2;i++), :

run again

for (int i =3;i<=3;i++), :

........

until for (int i =10;i<=10;i++), :

This gives correct results but as I mentioned this is not good coding, is there anyway to avoid that I just run oncefor (int i =1;i<=10;i++), :

My code is attached under"

public class RunAllPrograms {

static double [] AccuracyCal = new double [10];

static double [] ErrorCal = new double [10];

public static void main(String[] args) throws IOException{

// TestKillProcess J= new TestKillProcess();

String Rel = JOptionPane.showInputDialog ("Enter Relation name : ");

for (int i =3;i<=4;i++){

RunAllPrograms Y = new RunAllPrograms();

Y.deleteFile ("dataf/"+Rel+"/ProftFileClassification.txt");

Y.deleteFile ("dataf/"+Rel+"/plength.txt");

Y.deleteFile ("dataf/"+Rel+"/pwidth.txt");

Y.deleteFile ("dataf/"+Rel+"/slength.txt");

Y.deleteFile ("dataf/"+Rel+"/swidth.txt");

Y.deleteFile ("dataf/"+Rel+"/TrainingData.txt");

Y.deleteFile ("dataf/"+Rel+"/TestingData.txt");

Feras_SplitTrainingAndTesting A = new Feras_SplitTrainingAndTesting();

SplitAtributes B = new SplitAtributes();

FerasPrgMain C = new FerasPrgMain();

Statistics D = new Statistics();

FerasID3 E = new FerasID3();

SortClassification F = new SortClassification();

Prototypes G = new Prototypes();

Proaftn3 H = new Proaftn3();

Accuracy I = new Accuracy();

A.Start1(Rel,i);

B.Start2(Rel);

C.Start3(Rel);

D.Start4(Rel);

E.Start5(Rel);

F.Start6(Rel);

G.Start7(Rel);

H.Start8(Rel);

I.Start9(Rel);

AccuracyCal[i-1] = I.AccuracyVal;

ErrorCal[i-1]= I.ErrorVal;

Write( i, AccuracyCal[i-1] );

System.out.println(" Accuracy = "+ I.AccuracyVal + " %");

System.out.println(" Error rate = "+ I.ErrorVal + " %");

}// end for

double sum1=0, sum2=0;

for ( int j= 0; j<AccuracyCal.length; j++) {

sum1 = sum1+ AccuracyCal[j];

sum2 = sum2+ ErrorCal[j];

}

System.out.println(" Average Accuracy = "+ sum1/AccuracyCal.length + " %");

System.out.println(" Average Error rate = "+ sum1/ErrorCal.length + " %");

}

public static void deleteFile (String DelFile )

{

File myFile = new File(DelFile);

try

{

myFile.delete();

// System.out.println("Successfully deleted " + myFile.toString());

}

catch (SecurityException e)

{

System.out.println("Caught security exception trying to delete file " + myFile.toString());

}

}

public static void Write( int x, double Results )throws IOException

{

DecimalFormat myDecFormat = new DecimalFormat("####.00");

File appending = new File("RessultsNow.txt"); // Prototype file name

FileWriter appendingW = new FileWriter(appending, true);

BufferedWriter StartAppend = new BufferedWriter(appendingW);

StartAppend.write(x+"\t"+Results);

StartAppend.newLine();

StartAppend.close();

}

}>

[3990 byte] By [FNOa] at [2007-11-27 6:21:18]
# 1
1) I have no idea what you're asking.2) When you post code, please use[code] and [/code] tags as described in [url= http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips[/url] on the message entry page. It makes it much easier to read.
jverda at 2007-7-12 17:37:38 > top of Java-index,Java Essentials,Java Programming...
# 2

Hi,

I have a following program , this program call another classes .

my problem is that if I run loop to call the other classes, for example:

for (int i =3;i<=4;i++), I get a strange error saying :

java.io.FileNotFoundException: dataf\iris\TrainingData.txt (Access is denied)

But when I run the program for every single iteration for example

for (int i =1;i<=1;i++), :

run again

for (int i =2;i<=2;i++), :

run again

for (int i =3;i<=3;i++), :

........

until for (int i =10;i<=10;i++), :

I get correct results, no problem

I need 10 iteration for this code so, it is not convenient for every run to do it like this:

for (int i =1;i<=1;i++), :

run again

for (int i =2;i<=2;i++), :

run again

for (int i =3;i<=3;i++), :

........

until for (int i =10;i<=10;i++), :

This gives correct results but as I mentioned this is not good coding, is there anyway to avoid that ?

I just need to run my program once :

like this :

for (int i =1;i<=10;i++), :

My code is attached under"

public class RunAllPrograms {

static double [] AccuracyCal = new double [10];

static double [] ErrorCal = new double [10];

public static void main(String[] args) throws IOException {

// TestKillProcess J= new TestKillProcess();

String Rel = JOptionPane.showInputDialog ("Enter Relation name : ");

for (int i =3;i<=4;i++){

RunAllPrograms Y = new RunAllPrograms();

Y.deleteFile ("dataf/"+Rel+"/ProftFileClassification.txt");

Y.deleteFile ("dataf/"+Rel+"/plength.txt");

Y.deleteFile ("dataf/"+Rel+"/pwidth.txt");

Y.deleteFile ("dataf/"+Rel+"/slength.txt");

Y.deleteFile ("dataf/"+Rel+"/swidth.txt");

Y.deleteFile ("dataf/"+Rel+"/TrainingData.txt");

Y.deleteFile ("dataf/"+Rel+"/TestingData.txt");

Feras_SplitTrainingAndTesting A = new Feras_SplitTrainingAndTesting();

SplitAtributes B = new SplitAtributes();

FerasPrgMain C = new FerasPrgMain();

Statistics D = new Statistics();

FerasID3 E = new FerasID3();

SortClassification F = new SortClassification();

Prototypes G = new Prototypes();

Proaftn3 H = new Proaftn3();

Accuracy I = new Accuracy();

A.Start1(Rel,i);

B.Start2(Rel);

C.Start3(Rel);

D.Start4(Rel);

E.Start5(Rel);

F.Start6(Rel);

G.Start7(Rel);

H.Start8(Rel);

I.Start9(Rel);

AccuracyCal[i-1] = I.AccuracyVal;

ErrorCal[i-1]= I.ErrorVal;

Write( i, AccuracyCal[i-1] );

System.out.println(" Accuracy = "+ I.AccuracyVal + " %");

System.out.println(" Error rate = "+ I.ErrorVal + " %");

}// end for

double sum1=0, sum2=0;

for ( int j= 0; j<AccuracyCal.length; j++) {

sum1 = sum1+ AccuracyCal[j];

sum2 = sum2+ ErrorCal[j];

}

System.out.println(" Average Accuracy = "+ sum1/AccuracyCal.length + " %");

System.out.println(" Average Error rate = "+ sum1/ErrorCal.length + " %");

}

public static void deleteFile (String DelFile )

{

File myFile = new File(DelFile);

try

{

myFile.delete();

// System.out.println("Successfully deleted " + myFile.toString());

}

catch (SecurityException e)

{

System.out.println("Caught security exception trying to delete file " + myFile.toString());

}

}

public static void Write( int x, double Results )throws IOException

{

DecimalFormat myDecFormat = new DecimalFormat("####.00");

File appending = new File("RessultsNow.txt"); // Prototype file name

FileWriter appendingW = new FileWriter(appending, true);

BufferedWriter StartAppend = new BufferedWriter(appendingW);

StartAppend.write(x+"\t"+Results);

StartAppend.newLine();

StartAppend.close();

}

}>

FNOa at 2007-7-12 17:37:38 > top of Java-index,Java Essentials,Java Programming...
# 3

You're getting help in your other thread. Just stick to that one now.

Also, just putting code tags around your unindented code won't help. You need to properly indent it in your editor or IDE and then copy/paste from there into here, AND use code tags.

But do that in the other thread. Forget this one.

jverda at 2007-7-12 17:37:38 > top of Java-index,Java Essentials,Java Programming...