If you're doing this for a console based app (e.g. in a unit test) and intend to use the output to open a file for reading or writing, it's more helpful to use Platform.script.path
:
import "package:path/path.dart" show dirname, join;
import 'dart:io' show Platform;
main() {
print(join(dirname(Platform.script.path), 'test_data_file.dat');
}
The result of that command can be used with a File
object and be opened/read (e.g. if you have a unit test that needs to read/compare sample data, or a console program that needs to open a file relative to the current script for some other reason).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…