Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

import java.io.IOException;

public class Main {
    private static String T_FLASH_PATH = "/storage/sdcard1";

    public static double getTFlashCardSpace() {
        File dir;
        if (isTFlashCardExists()) {
            dir = new File(T_FLASH_PATH);
            return dir.getTotalSpace() * 0.8;
        }

        return 0;
    }

    public static boolean isTFlashCardExists() {
        boolean tfExistsFlag = false;
        tfExistsFlag = new File(T_FLASH_PATH, "Android").exists();

        if (getStorageDirWhenInsertSdcard() != null && testNewTfFile() == true) {
            tfExistsFlag = true;
        }
        return tfExistsFlag;
    }

    public static File getStorageDirWhenInsertSdcard() {
        File dir;
        try {
            dir = new File(T_FLASH_PATH, getMainDirName());
        } catch (Exception e) {
            return null;
        }

        if (!dir.exists()) {
            dir.mkdirs();
        }

        return dir;
    }

    public static boolean testNewTfFile() {
        File testFile = new File(T_FLASH_PATH, "testNewFile");
        boolean returnFlag = false;
        if (!testFile.exists()) {
            try {
                if (testFile.createNewFile()) {
                    returnFlag = true;
                    testFile.delete();
                }
            } catch (IOException e) {
                returnFlag = false;
            }
        } else {
            testFile.delete();
            returnFlag = true;
        }
        return returnFlag;
    }

    public static String getMainDirName() {
        return "/aiowner";
    }
}