Java tutorial
//package com.java2s; /* * Copyright (C) 2004-2016 Savoir-faire Linux Inc. * * Author: Romain Bertozzi <romain.bertozzi@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ import android.content.Context; import android.text.TextUtils; import java.io.File; import java.io.FileOutputStream; public class Main { /** * Saves a vcard string to an internal new vcf file. * @param vcard the string to save * @param filename the filename of the vcf * @param context the context used to open streams. */ public static void saveToDisk(String vcard, String filename, Context context) { if (TextUtils.isEmpty(vcard) || TextUtils.isEmpty(filename) || context == null) { return; } String path = context.getFilesDir().getAbsolutePath() + File.separator + "peer_profiles"; File peerProfilesFile = new File(path); if (!peerProfilesFile.exists()) peerProfilesFile.mkdirs(); FileOutputStream outputStream; try { outputStream = new FileOutputStream(path + "/" + filename); outputStream.write(vcard.getBytes()); outputStream.close(); } catch (Exception e) { e.printStackTrace(); } } }