js怎么读取服务器里的txt内容到变量,然后跟另外一个对比大小?
var txt1="",txt2="";
fetch("第1个txt文件名")then(r=>rtext())then(t=>{
txt1=t;
fetch("第2个txt文件名")then(r=>rtext())then(t=>{
txt2=t;
//然后比较txt1和txt2的大小即可
});
});
/
读取某个文件夹下的所有文件
/
public static boolean readfile(String filepath) throws FileNotFoundException, IOException {
try {
File file = new File(filepath);
if (!fileisDirectory()) {
Systemoutprintln("文件");
Systemoutprintln("path=" + filegetPath());
Systemoutprintln("absolutepath=" + filegetAbsolutePath());
Systemoutprintln("name=" + filegetName());
} else if (fileisDirectory()) {
Systemoutprintln("文件夹");
String[] filelist = filelist();
for (int i = 0; i < filelistlength; i++) {
File readfile = new File(filepath + "\\" + filelist[i]);
if (!readfileisDirectory()) {
Systemoutprintln("path=" + readfilegetPath());
Systemoutprintln("absolutepath="
+ readfilegetAbsolutePath());
Systemoutprintln("name=" + readfilegetName());
} else if (readfileisDirectory()) {
readfile(filepath + "\\" + filelist[i]);
}
}
}
} catch (FileNotFoundException e) {
Systemoutprintln("readfile() Exception:" + egetMessage());
}
return true;
}
0条评论