function readfile(){
var fso,str,file;
getFname();
fso = new ActiveXObject("Scripting.FileSystemObject");
str = "没有打开文件";
if (fso.FileExists(fname)){
file=fso.OpenTextFile(fname,1,true,-2);
str=file.readall();
document.write(str);
}
}
打开的文本文件是乱码
改成file=fso.OpenTextFile(fname,1,true,-1);
改成file=fso.OpenTextFile(fname,1,true,0);
输出均有问题
还有,使用type XX.txt输出也是乱码但是使用记事本打开的能正常显示~~
急求助
解决方案 »
- jsp中如何在编辑多行文字的时候添加表情
- 求助!JavaScript制作右下角信息提示窗口
- JAVA SCRIPT里面DOCUMENT.ALL输出时如何使用变量
- 问下关于js中弹窗操作的问题,实在不会了
- FCKEditor中,怎样实现字符数的实时统计(急100分)
- 一个正则问题,,给高手的问题,满分100
- 各位大哥,怎么在文本框中使输入的html代码不起作用啊?急!!
- VBSCRIPT中的chr()/asc()函数在JAVASCRIPT中有吗?
- easyUI的form加载数据onLoadSuccess的用法
- JQ实现,哪位前端大佬可以写个小例子
- 100分求助求助?
- jsp中JQUERY 如何获得 CHECKBOX是否被选中?--不使用ONCLICK属性
输出源代码为:public synchronized static boolean WriteFile(String path, String Tcontent,boolean append) {
if (path != null && path.trim().length() != 0) {
try{
FileOutputStream fos = new FileOutputStream(path, append);
OutputStreamWriter ow = new OutputStreamWriter(fos, "utf-8");
PrintWriter pw = new PrintWriter(ow);
pw.write(Tcontent.toString());
pw.flush();
pw.close();
ow.close();
fos.close();
return true;
} catch (Exception eq) {
eq.printStackTrace();
return false;
} } else {
return false;
}
}
function readfile(fname){
var fso,str,file;
fso = new ActiveXObject("Scripting.FileSystemObject");
str = "没有打开文件";
if (fso.FileExists(fname)){
file=fso.OpenTextFile(fname,1,true,-1);
str=file.readall();
}
document.write(str);
}
readfile("d:\\1.txt");
我这里显示正常
file=fso.OpenTextFile(fname,1,true,0);
<script>
function readfile(){
var fso,str,file;
fname="a.txt";
fso = new ActiveXObject("Scripting.FileSystemObject");
str = "没有打开文件";
if (fso.FileExists(fname)){
file=fso.OpenTextFile(fname,1,true,-2);
str=file.readall();
document.write(str);
}
}
readfile();
</script>我运行了这个代码在我机器上的IE6,什么内容都没有,就只有一个提示是否交互,奇怪了。
fso OpenTextFile方法说明文档信息 1页 转贴至 人人网QQ空间更多...举报 ... fso(524) filename(2388) format(6771) create(17079) object(13278) iomode...
JS的html也是utf-8格式,而且在meta里也设置编码为utf-8,可是显示的时候却是这样:
没有打开文件锘縡so OpenTextFile鏂规硶璇存槑鏂囨。淇℃伅 1椤?杞创鑷?浜轰汉缃慟Q绌洪棿鏇村...涓炬姤 ... fso(524) filename(2388) format(6771) create(17079) object(13278) iomode...
附加HTML内容如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>222</title>
<script>
function readfile(){
var fso,file,str="";
fname="b.txt";
fso = new ActiveXObject("Scripting.FileSystemObject");
str = "没有打开文件";
if (fso.FileExists(fname)){
file=fso.OpenTextFile(fname,1,true,0);
while (!file.AtEndOfStream)
{
str=str+file.readall();
}
document.write(str);
}
}
readfile();
</script></head>
<body>
</body>
</html>