PhantomJS - copy 方法
此方法有助于将文件从一个位置复制到另一个位置。它需要两个参数。第一个参数是源文件,第二个参数是文件路径,必须将文件复制到该路径。如果源文件或目标文件不存在,它将抛出错误。
语法
其语法如下 −
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.html

