我已经将文件路径保存在变量中,并且我想通过使用路径包https://pub.dev/packages/path获得文件类型的扩展名,到目前为止,我设法通过像这样分割字符串来做到这一点
final path = "/some/path/to/file/file.dart";
print(path.split(".").last); //prints dart
使用路径包有什么方法可以实现这一点吗?
您可以使用extension
function中的extension
从文件路径获取扩展名:
path
package
如果文件具有多个扩展名,例如path
,则可以指定可选的import 'package:path/path.dart' as p;
final path = '/some/path/to/file/file.dart';
final extensions = p.extension(path); // '.dart'
参数:
file.dart.js