Originally Posted by
atgoodprogram
Ok, thanks, I ll try that out and give feedback
I ve tried it and Its not working, its bringing a nullpointer error, or nothing is being written to all the outputfiles, even the first file (TextDoc2) where all the jobs are first generated into has but only one job in it then that one job alone is sent to its category of output file.
Here is the code :
<
import java.io.FileNotFoundException;
import utilities.FileOutput;
public class SendToOutputFile
{
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException
{
FileOutput file = new FileOutput("C:/Users/Desktop/TextDoc2.txt", null);
SingleJob[] someJobs = SingleJob.createManyJobs(0, 30);
System.out.println("Moving through jobs one by one with a loop:");
for(int i=0; i<someJobs.length; i++)
{
SingleJob job = someJobs[i];
String jobAsString = job.toString();
try
{
file.open();
file.println(jobAsString, true);
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
}
System.out.println("Creating a dispatcher");
JobDespatcher despatcher = new JobDespatcher();
despatcher.despatch(someJobs);
for(JobPriority priority:JobPriority.values())
{
FileOutput fileA = new FileOutput("C:/Users/Desktop/TextDocA.txt", null);
FileOutput fileB = new FileOutput("C:/Users/Desktop/TextDocB.txt", null);
FileOutput fileC = new FileOutput("C:/Users/Desktop/TextDocC.txt", null);
FileOutput fileD = new FileOutput("C:/Users/Desktop/TextDocD.txt", null);
System.out.println("Getting all jobs with priority " + priority);
SingleJob[] jobs = despatcher.getJobs(priority);
fileA.open();
fileB.open();
fileC.open();
fileD.open();
for(SingleJob job:jobs)
{
String jobAsString = job.toString();
if (priority == JobPriority.VeryHigh)
{
try
{
fileA.println(jobAsString, true);
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
}
else if ( priority == JobPriority.High){
try
{
fileB.println(jobAsString, true);
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
}
else if (priority == JobPriority.Medium)
{
try
{
fileC.println(jobAsString, true);
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
}
else
{
try
{
fileD.println(jobAsString, true);
}
catch(Exception e)
{
e.printStackTrace(System.err);
}
finally
{
fileA.close();
fileB.close();
fileC.close();
fileD.close();
}
}
}
}
}
}
>