[Pogamut-list] Writing to an external file

Tomus pogamut-forum at artemis.ms.mff.cuni.cz
Fri Jul 17 17:33:22 CEST 2009


Writing to an external file

Author: Tomus

Hi,

I want to write results to an external file - a simple .txt or .xls files and I have tried the following coding and I get a "java.io.FileNotFoundException: c:\MonteCarlo.xls (Access is denied)" exception. As far as I understand that you cannot write files from a server. Is there an other way to file values to an external file.

public static void WriteOutputData(String filename, ArrayList locations)
    {
        String fileName;
        BufferedWriter writer;
        boolean fileExists;
        
        if(!filename.endsWith(fileExtension)){
            fileName = filename + fileExtension;
        }else{
            fileName = filename;
        }
        
        try{
            fileExists = new File(fileName).exists();
            
            if(fileExists){
                writer = new BufferedWriter(new FileWriter(fileName, true));
                writer.newLine();
                // write data to file
                writer.close();
            }else{
                writer = new BufferedWriter(new FileWriter(fileName));
                // write data to file
                for(int l = 0; l < locations.size(); l++){
                    writer.write(locations.get(l).getNavPoint().location.toString() + "\t" + Double.toString(locations.get(l).getBelief()));
                }
                writer.close();
            }
        }catch(IOException e){
            e.printStackTrace();
        }
    }

Thomas





More information about the Pogamut-list mailing list