如何获取Dart中文件的名称? [英] How can I get the name of a file in Dart?
本文介绍了如何获取Dart中文件的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现我无法以简单的方式取得档案名称:(
Dart代码:
文件file = new File(/ dev / dart / work / hello / app.dart);
如何获取文件名 app.dart
?
我没有找到一个API,所以我做的是:
var path = file.path;
var filename = path.split(/)。last;
有没有更简单的解决方案?
解决方案
http://pub.dartlang.org/packages/pathrel =nofollow>路径包:
import'dart:io';
pre>
import'package:path / path.dart';
main(){
文件文件= new文件(/ dev / dart / work / hello / app.dart);
String filename = basename(file.path);
}
I found I can't get the name of a file in a simple way :(
Dart code:
File file = new File("/dev/dart/work/hello/app.dart");
How to get the file name
app.dart
?I don't find an API for this, so what I do is:
var path = file.path; var filename = path.split("/").last;
Is there any simpler solution?
解决方案You can use the path package :
import 'dart:io'; import 'package:path/path.dart'; main() { File file = new File("/dev/dart/work/hello/app.dart"); String filename = basename(file.path); }
这篇关于如何获取Dart中文件的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文