import java.nio.file.*;

public class dht11 {
    public static void main(String... args) {
        String dir = "/sys/bus/iio/devices/iio:device0";
        String temp = "in_temp_input";
        String hum = "in_humidityrelative_input";
        boolean done = false;

        while (!done) {
            try {
                String temperature = Files.lines(Paths.get(dir,temp)).
                 findFirst().orElse("0");
                String humidity = Files.lines(Paths.get(dir,hum)).
                 findFirst().orElse("0");
                System.out.printf(
                 "Temperature: %.1fC  %.1fF  Humidity: %.1f%%\n",
                 Double.valueOf(temperature) / 1000.0,
                 Double.valueOf(temperature) / 1000.0 * 9.0 / 5.0 + 32.0,
                 Double.valueOf(humidity) / 1000.0);
                done = true;
            } catch (Exception ioe) {
                //System.out.println(ioe);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ie) {
                    ie.printStackTrace();
                }
            }
        }
    }
}