Is there a way to take the BIOS date and save it in a variable?

0

I can not find a way to take the BIOS date to make a Demo for a Java application but nothing. Does anybody have an idea? I've tried this:

Date fecha12 = new Date(System.currentTimeMillis());

but take the windows date that can be changed and the demo can be corrupted if the date is changed

    
asked by AppleFer 31.12.2018 в 23:14
source

1 answer

0

I do not know a way to directly access that information from java but an alternative is to use the systeminfo command of the windows console (CMD) which also provides us with additional information regarding our machine.

The only disadvantage is that it is tied to the windows platform but I suppose that in other systems there are similar alternatives.

I'll give you an example:

public class PCInformation {

        public static void main(String[] args) throws IOException {
            System.out.println("Bios Date is : "+getBiosDate());
        }

        public static String getBiosDate() throws IOException {
            Runtime runtime = Runtime.getRuntime();
            String[] commands = { "systeminfo" };
            Process process = runtime.exec(commands);

            BufferedReader lineReader = 
                    new BufferedReader(new InputStreamReader(process.getInputStream()));
            String biosInfo = lineReader.lines()
                                        .filter(line -> line.contains("BIOS"))
                                        .findFirst().get();


            String biosDate = biosInfo.substring(biosInfo.indexOf(",")+1).trim();
            return biosDate;
        }


}

* The function returns a String, I guess for you it will not be complicated to make the conversion to Date or any other type of object for handling dates.

    
answered by 01.01.2019 в 18:23