如何删除文本文件中的数据?

时间:2011-11-28 16:51:30

标签: android text-files delete-file

我有这段代码:

public void makeFile(String sFileName, int gene_ration)
    {
        try
        {
            //deleteFile("genetic_algorithm.txt"); 
            if (!myfile.exists()) {
                myfile.mkdirs();
            }

            File gpxfile = new File(myfile, sFileName);
            FileWriter writer = new FileWriter(gpxfile, true);
            writer.append("Generation " + gene_ration + "\r\n");
            for(chromosomesNumber = 0; chromosomesNumber < indexOfChromosomes ; chromosomesNumber++)
            {   writer.append(chromosomesNumber + ". " );
                writer.append(population[chromosomesNumber] + " ");
                writer.append("Nilai fitness : " + population[chromosomesNumber].fitness + "\r\n");
            }
            writer.append("\r\n");
            writer.flush();
            writer.close();
        }
        catch(IOException e)
        {
             e.printStackTrace();
             String importError = e.getMessage();
        }
    }

我想在每次编译时删除textfile上的数据,然后再将数据添加到textfile中。我怎样才能做到这一点?任何的想法?

1 个答案:

答案 0 :(得分:0)