file reader java script code example
Example 1: java how to read file extension
private static String getFileExtension(File file) {
String extension = "";
try {
if (file != null && file.exists()) {
String name = file.getName();
extension = name.substring(name.lastIndexOf("."));
}
} catch (Exception e) {
extension = "";
}
return extension;
}
Example 2: read file using shell script
#!/bin/bash
input="/path/to/txt/file"
while IFS= read -r line
do
echo "$line"
done < "$input"