Android Open Source - FAST File Helper






From Project

Back to project page FAST.

License

The source code is released under:

GNU General Public License

If you think the Android project FAST listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.ligi.axt.helpers;
//from   www.  ja v  a2  s . c o  m
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;

public class FileHelper {
    private final File file;

    public FileHelper(File file) {
        this.file = file;
    }

    /**
     * reads a file to a string
     *
     * @return the content of the file
     * @throws IOException
     */
    public String loadToString() throws IOException {
        return loadToString(Charset.defaultCharset());
    }

    public String loadToString(Charset charset) throws IOException {
        FileInputStream stream = new FileInputStream(file);
        FileChannel fc = stream.getChannel();
        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
        fc.close();
        stream.close();
        return charset.decode(bb).toString();
    }

    public boolean writeString(String string) {
        try {
            FileWriter fileWriter = new FileWriter(file);
            fileWriter.write(string);
            fileWriter.close();
            return true;
        } catch (IOException e) {
            return false;
        }
    }

    public boolean deleteRecursive() {
        return deleteRecursive(file);
    }

    public boolean deleteRecursive(File file2delete) {
        if (!file2delete.isDirectory()) {
            return false;
        }

        for (String child:file2delete.list()) {
            File temp = new File(file2delete, child);
            if (temp.isDirectory()) {
                deleteRecursive(temp);
            } else {
                temp.delete();
            }
        }

        return file2delete.delete();

    }
}




Java Source Code List

org.ligi.axt.helpers.ActivityHelper.java
org.ligi.axt.helpers.ContextHelper.java
org.ligi.axt.helpers.FileHelper.java
org.ligi.axt.helpers.ResolveInfoHelper.java
org.ligi.axt.helpers.ViewHelper.java
org.ligi.axt.simplifications.SimpleTextWatcher.java
org.ligi.fast.App.java
org.ligi.fast.TargetStore.java
org.ligi.fast.TargetStore.java
org.ligi.fast.TargetStore.java
org.ligi.fast.background.AppInstallOrRemoveReceiver.java
org.ligi.fast.background.BackgroundGatherAsyncTask.java
org.ligi.fast.background.BaseAppGatherAsyncTask.java
org.ligi.fast.model.AppIconCache.java
org.ligi.fast.model.AppInfoList.java
org.ligi.fast.model.AppInfoSortByLabelComparator.java
org.ligi.fast.model.AppInfoSortByMostUsedComparator.java
org.ligi.fast.model.AppInfo.java
org.ligi.fast.model.DynamicAppInfoList.java
org.ligi.fast.settings.AndroidFASTSettings.java
org.ligi.fast.settings.FASTSettings.java
org.ligi.fast.testing.AppInfoTestBase.java
org.ligi.fast.testing.MutableFastSettings.java
org.ligi.fast.testing.TheAppIconCache.java
org.ligi.fast.testing.TheAppInfoStore.java
org.ligi.fast.testing.TheAppInfo.java
org.ligi.fast.testing.TheSearchActivity.java
org.ligi.fast.ui.AppActionDialogBuilder.java
org.ligi.fast.ui.AppInfoAdapter.java
org.ligi.fast.ui.FASTSettingsActivity.java
org.ligi.fast.ui.HelpDialog.java
org.ligi.fast.ui.HelpDialog.java
org.ligi.fast.ui.IconDimensions.java
org.ligi.fast.ui.LoadingDialog.java
org.ligi.fast.ui.SearchActivity.java
org.ligi.fast.util.AppInfoListStore.java
org.ligi.fast.util.PackageListSerializer.java
org.ligi.fast.util.StringUtils.java
org.ligi.fast.util.UmlautConverter.java