我知道這裏有幾個關於計算器的主題,但是我找不到解決我的問題的任何問題。不可能在Android中創建CSV文件,總是失敗
我已成功實現(它已測試)SharedPreferences來保存我的應用程序數據,現在我的目標是將該數據導出到CSV文件。
這就是我要怎樣做:
public void saveCSVFile(List<PessoaClass> data) {
PrintWriter writer;
String strFilePath = "C:\\users\\ricardo\\desktop\\testesCSV\\pessoas.csv";
try {
File file = new File(strFilePath);
if(!file.exists())
file = new File(strFilePath);
writer = new PrintWriter(new FileWriter(file,true));
for(int i = 0; i < data.size(); i++){
writer.print(data.get(i).getAge());
writer.print(data.get(i).getSex());
writer.print(data.get(i).getName());
writer.print(data.get(i).getEmail());
writer.print("\r\n");
}
writer.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
我一直運行到它的「java.io.FileNotFoundException錯誤:C:\用戶\裏卡多\桌面\ testesCSV \ pessoas.csv(讀-only文件系統)」
爲了與CSVWriter庫進行測試,我也嘗試以下示例代碼:
public void saveCSVFile() {
String csv = "C:\\users\\ricardo\\desktop\\testesCSV\\pessoas.csv";
try {
CSVWriter writer = new CSVWriter(new FileWriter(csv));
List<String[]> imprimir = new ArrayList<>();
imprimir.add(new String[]{"India", "New Delhi"});
imprimir.add(new String[]{"United States", "Washington D.C"});
imprimir.add(new String[]{"Germany", "Berlin"});
writer.writeAll(imprimir);
writer.close();
}
catch(IOException e){
e.printStackTrace();
}
}
誤差是相同的。 我試圖以管理員身份運行Android Studio - 沒有成功。
我不明白是什麼錯誤,因爲我正試圖寫入我的個人計算機桌面,而不是像沒有root權限的應用程序/應用程序一樣在網站上的其他用戶。
此應用程序旨在運行在非根設備。
任何幫助表示讚賞!
Android不具有 '桌面'。每個應用都在自己的沙箱中運行。 – Barns