[Solved]Write Method Isvalidfilename String Filename String Sys Returns True Filename Represents V Q37291552
Write a method isValidFilename(String filename, String sys)which returns true if filename represents a valid file nameaccording to the rules of the operating system in the secondparameter sys, or false otherwise. Use regular expressions to matchthe following rules for different systems. You can assume thatfilename will never be passed as an empty string and will alwaysinclude a file extension (i.e., file type).
If the operating system sys is “Windows”, then:
The file name cannot contain any leading or trailingwhitespace characters
The file name cannot contain any of these special characters:/ ? < > : * | . “
The file name cannot end with com1, com2, …, or com9 (i.e.,com followed by exactly one digit between 1 and 9, inclusive)
The file name is separated from the file extension by exactlyone period character
The file extension can only contain lower case alphabetletters
The file extension length is between 2 and 6 characters(inclusive)
If the operating system sys is “Mac” or “Linux”, then:
The file name cannot contain a period “.” character or a colon“:” character
The file name is separated from the file extension by exactlyone period character
The file extension can only contain alphabet letters (uppercase or lower case)
The file extension length is between 2 and 6 characters(inclusive)
Examples: isValidFilename(“homework5.java”, “Linux”) returnstrue isValidFilename(“hamlet.shakespeare”, “Mac”) returns falseisValidFilename(“rom_com3.txt”, “Windows”) returns false
Expert Answer
Answer to Write a method isValidFilename(String filename, String sys) which returns true if filename represents a valid file name … . . .
OR

