Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.os.Build;

import java.io.BufferedInputStream;

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.util.Properties;

public class Main {
    static String getDataDir(final Context c) {
        final String defaultDataDir = String.format("%s/.bitcoin", getDir(c).getAbsolutePath());
        try {
            final Properties p = new Properties();
            p.load(new BufferedInputStream(new FileInputStream(getBitcoinConf(c))));
            return p.getProperty("datadir", defaultDataDir);
        } catch (final IOException e) {
            return defaultDataDir;
        }
    }

    static File getDir(final Context c) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            return c.getNoBackupFilesDir();
        else
            return c.getFilesDir();
    }

    static String getBitcoinConf(final Context c) {
        return String.format("%s/.bitcoin/bitcoin.conf", getDir(c).getAbsolutePath());
    }
}