we want to write the content of an ArrayList (images with a longitude and latitude) to a file (.csv or txt, doesn't matter).
We know that there is something wrong with the bw.write(), but we didn't get how we can manage it. Someone an idea?

Here is our code:

/**
 * Test if stadium contains image 
 */
public void RemStaImSB(){
    Mbb mbb = new Mbb(1,new Point (1,-0.192423,51.480788),new Point(2,-0.189537,51.482646));
    int i = 0;
    imgOut = new ArrayList<Image>();
    for(Image im: this.img){

        if(mbb.piMbb(im)==false){
            imgOut.add(im);
        }
        i++;
    }
    System.out.println("Reporting the images "+i); }


/**
 * Test if stadium contains image 
 */    
public void main() throws Exception{
//Declarations
File outputFile;
BufferedWriter bw;
//Create outputFile object
outputFile = new File ("Chelsea.txt");
//Create stream - file is created
bw= new BufferedWriter(new FileWriter(outputFile));

//Send data thorugh file writer
bw.write(imgOut.lat & imgOut.lon);
//Close the writer
bw.close();

}

有帮助吗?

解决方案

In this line:

bw.write(imgOut.lat & imgOut.lon);

You're writing the result of the bitwise AND operation of your latitude and longitude. You should write the values by separate:

bw.write(imgOut.lat);
bw.write(imgOut.lon);

But this will write the data as single char. Instead, it would be better if you print a String representation of the data. Since you're writing to a csv, you can separate the data by commas:

bw.write(imgOut.lat + "," + imgOut.lon);

其他提示

If you're writing to a .csv file, you can do this:

bw.write(imgOut.lat + "," + imgOut.lon);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top