load Address from /sys/ folder - Android Map

Android examples for Map:Address

Description

load Address from /sys/ folder

Demo Code


//package com.java2s;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    private static String loadAddress(final String interfaceName) {
        try {/*from  w ww .  j  a  va 2  s. c  o m*/
            final String filePath = "/sys/class/net/" + interfaceName
                    + "/address";
            final StringBuilder fileData = new StringBuilder(1000);
            final BufferedReader reader = new BufferedReader(
                    new FileReader(filePath), 1024);
            final char[] buf = new char[1024];
            int numRead;

            String readData;
            while ((numRead = reader.read(buf)) != -1) {
                readData = String.valueOf(buf, 0, numRead);
                fileData.append(readData);
            }

            reader.close();
            return fileData.toString();
        } catch (IOException e) {
            return null;
        }
    }
}

Related Tutorials