js下Ajax读取txt文件内容与Java 写入读取txt

这篇博客汇总了使用JavaScript的AJAX技术读取和写入TXT文件的方法,并提供了多个参考链接,同时介绍了Java读取和操作TXT文件的不同途径。

js ajax读取 写入 

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>js中的Ajax经典实例</title>
    <script type="text/javascript" >
        function ajax() {
            //1.声明异步请求对象:
            var xmlHttp = null;
            if (window.ActiveXObject) {
                // IE6, IE5 浏览器执行代码
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } else if (window.XMLHttpRequest) {
                // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
                xmlHttp = new XMLHttpRequest();
            }
            //2.如果实例化成功,就调用open()方法:
            if (xmlHttp != null) {
                xmlHttp.open("get", "songs.txt", true);
                xmlHttp.send();
                xmlHttp.onreadystatechange = doResult; //设置回调函数                 
            }
            function doResult() {
                if (xmlHttp.readyState == 4) { //4表示执行完成
                    if (xmlHttp.status == 200) { //200表示执行成功
                        document.getElementById("resText").innerHTML = xmlHttp.responseText;
                    }
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div id="resText"></div>
        <input type="button" value="点击获得文本内容" onclick="ajax();"/>
    </form>
</body>
</html>

js写入:https://blog.csdn.net/zhengyikuangge/article/details/72848789

https://www.cnblogs.com/eedc/p/6057391.html

java 部份参考大神:https://blog.csdn.net/milletguo/article/details/80144290

https://www.cnblogs.com/fulucky/p/9636090.html

https://blog.csdn.net/qq_23974323/article/details/80003815

https://blog.csdn.net/sinat_22797429/article/details/53118365

https://blog.csdn.net/qq78442761/article/details/79063901

写入:

File file =new File(request.getSession().getServletContext().getRealPath("/")+"js/system/read.txt");
			Writer out =new FileWriter(file);
			String data=privateString;
			out.write(data);
			out.close();

java 获取路径的各种方法https://www.cnblogs.com/guoyuqiangf8/p/3506768.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值