- 文件系统模块
- PhantomJS - 属性
- PhantomJS - 方法
- 系统模块
- PhantomJS - 属性
- 网络服务器模块
- PhantomJS - 属性
- PhantomJS - 方法
- 其他
- 命令行界面
- PhantomJS - 屏幕捕获
- PhantomJS - 页面自动化
- PhantomJS - 网络监控
- PhantomJS - 测试
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用资源
- PhantomJS - 快速指南
- PhantomJS - 有用资源
- PhantomJS - 讨论
PhantomJS - 复制
此方法有助于将文件从一个位置复制到另一个位置。它有两个参数。第一个参数是源文件,第二个参数是文件路径,必须将文件复制到该路径。如果源文件或目标文件不存在,它会抛出错误。
语法
其语法如下 -
var fs = require('fs');
fs.copy(sourcefile,destinationfile);
示例
var fs = require('fs');
var system = require('system');
var path1 = system.args[1];
var path2 = system.args[2];
console.log("Checking to see if source is a file:" + fs.isFile(path1));
console.log("Checking to see if destination is a file:" + fs.isFile(path2));
console.log("copying file from source to destination");
fs.copy(path1,path2);
console.log("Checking to see if destination is a file:" + fs.isFile(path2));
console.log("contents from file are:");
console.log(fs.read(path2));
上述程序生成以下输出。
var fs = require('fs');
var system = require('system');
var path1 = system.args[1];
var path2 = system.args[2];
console.log("Checking to see if source is a file:" + fs.isFile(path1));
console.log("Checking to see if destination is a file:" + fs.isFile(path2));
console.log("copying file from source to destination");
fs.copy(path1,path2);
console.log("Checking to see if destination is a file:" + fs.isFile(path2));
console.log("contents from file are:");
console.log(fs.read(path2));
phantomjs_file_system_module_methods.htm
广告