2013-05-10 3 views
1

Я пытался создать новый файл, данные в списке массива:Простой способ создать новый файл в Android

ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); 

nameValuePairs.add(new BasicNameValuePair("photos", image_str)); 
nameValuePairs.add(new BasicNameValuePair("UserId", userId)); 

Я хочу, чтобы создать файл, хранящий nameValuesPairs, который является ArrayList ,

Как создать файл в Android ??? Предпочтительно простой способ, используя массив, фотографии и другие.

ответ

0

Чтобы создать файл во внешнем хранилище для сохранения изображений и т.д., обратитесь к this documentation

Чтобы создать файл на внутренней памяти см this documentation.

0

Вот как я это делаю.

// First make sure we have SD card access 
private boolean ensureSDCardAccess(String directoryPath) { 
    File file = new File(directoryPath); 
    if (file.exists()) {    // Check if directory already exits 
     return true; 
    } else if (file.mkdirs()) {  // Create if doesn't exists already 
     return true; 
    } 
    return false; 
} 

// Now create file 
public void create file(String directoryName, String fileName) 
{ 
    String directoryPath = Environment.getExternalStorageDirectory() + directoryName; 
    if (ensureSDCardAccess(directoryPath)) { 
     String filePath = directoryPath + fileName; 
     File file = new File(filePath); 
     FileOutputStream fos; 
     try { 
      fos = new FileOutputStream(file); 
      // Write to the file    
      fos.close(); 
     } catch (FileNotFoundException e) { 
      Log.e("Panel", "FileNotFoundException", e); 
     } catch (IOException e) { 
      Log.e("Panel", "IOEception", e); 
     } 
} 
Смежные вопросы