<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<title>Java内存映射，上G大文件轻松处置-思洋互动</title>
		<meta name="keywords" content="Java内存映射，上G大文件轻松处置">
	    <meta name="description" content="内存映射文件(Memory-mappedFile)，指的是将一段虚拟内存逐字节映射于一个文件，使得应用程序处置文件好像访问主内存（但在真正运用到这些数据前却不会耗费物理内存，也不会有读写磁...">
		<meta name="renderer" content="webkit" />
		<link href="/css/main.css?v=39" rel="stylesheet">
		<link href="/css/base.css?v=39" rel="stylesheet">
        <link href="/css/swiper-3.4.2.min.css" rel="stylesheet">
		<script type="text/javascript" src="/js/jquery.min.js"></script>
        <script type="text/javascript" src="/js/swiper-3.4.2.min.js"></script>
		<!--[if lt IE 9]>
            <script src="/js/html5shiv.min.js"></script>
            <script src="/js/respond.min.js"></script>
            <link href="/css/ie.css" rel="stylesheet">
        <![endif]-->
		<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?8914d517c927d8e794148d05e387fb17";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
<link rel="canonical" href="https://www.ciya.cn/article/3750.html">
		</head>
	<body class="no-banner">
		<div class="container">
			<div class="header">
	<div class="header-top">
		<div class="w1700">
			<a href="https://www.ciya.cn/"><img src="/images/logo.png?v=2"></a>
		</div>
	</div>
	<div class="header_b">
		<header class="slide">
			<div id="navToggle" class="menu-handler">
				<span class="burger burger-1 trans"></span>
				<span class="burger burger-2 trans-fast"></span>
				<span class="burger burger-3 trans"></span>
			</div>
		</header>
	</div>
	<nav class="slide">
		<div class="w1700">
			<a class="index" href="/"></a>
			<ul>
								<li><a href="https://www.ciya.cn/case/12.html">项目案例</a></li>
								<li><a href="https://www.ciya.cn/website/9.html">网站建设</a></li>
								<li><a href="https://www.ciya.cn/marketing/10.html">网络营销</a></li>
								<li><a href="https://www.ciya.cn/media/11.html">新媒体</a></li>
								<li class="active"><a href="https://www.ciya.cn/news/16.html">动态</a></li>
								<li><a href="https://www.ciya.cn/about/8.html">关于</a></li>
								<li><a href="https://www.ciya.cn/contact/13.html">联系</a></li>
							</ul>
		</div>
	</nav>
</div>            <div class="content slide">
                <div class="position bgf1">
                    <div class="w1700">
                        <a href="https://www.ciya.cn/">首页 ></a>
                        <a href="https://www.ciya.cn/news/16.html">动态 ></a>
                        <a href="https://www.ciya.cn/news/35.html">网站知识</a>
                    </div>
                </div>
                <div class="case-type">
                    <div class="w1700">
                                                <a href="https://www.ciya.cn/news/32.html" >品牌合作</a>
                                                <a href="https://www.ciya.cn/news/31.html" >新闻动态</a>
                                                <a href="https://www.ciya.cn/news/38.html" >网站建设</a>
                                                <a href="https://www.ciya.cn/news/41.html" >网站制作</a>
                                                <a href="https://www.ciya.cn/news/40.html" >网站设计</a>
                                                <a href="https://www.ciya.cn/news/42.html" >运营推广</a>
                                                <a href="https://www.ciya.cn/news/35.html"  class="active">网站知识</a>
                                            </div>
                </div>
                <div class="padding-tb80">
                    <div class="w1700 clear">
                        <div class="fl xwxq-l">
                            <div class="noselettext">
                                <div class="xwxq-title mg-bt60 wow slideUp">
                                    <h1 class="mg-bt35">Java内存映射，上G大文件轻松处置</h1>
                                    <span>时间：2023-05-17</span>
                                </div>
                                <div class="edit2 mg-bt60 wow slideUp">
                                                                        <p>内存映射文件(Memory-mappedFile)，指的是将一段虚拟内存逐字节映射于一个文件，使得应用程序处置文件好像访问主内存（但在真正运用到这些数据前却不会耗费物理内存，也不会有读写磁盘的操作），这要比直接文件读写快几个数量级。<br />
略微解释一下虚拟内存（很明显，不是物理内存），它是计算机系统内存管理的一种技术。像施了妖法一样使得应用程序以为它具有连续的可用的内存，实践上呢，它通常是被分隔成多个物理内存的碎片，还有局部暂时存储在外部磁盘存储器上，在需求时停止数据交流。<br />
内存映射文件主要的用途是增加I/O性能，特别是针对大文件。关于小文件，内存映射文件反而会招致碎片空间的糜费，由于内存映射总是要对齐页边境，最小单位是4KiB，一个5KiB的文件将会映射占用8KiB内存，也就会糜费3KiB内存。<img class="aligncenter size-medium wp-image-4822" src="https://zzzjtd.com/wp-content/uploads/2019/07/208-1-300x240.jpg" alt="java" width="300" height="240" /><br />
java.nio包使得内存映射变得十分简单，其中的中心类叫做MappedByteBuffer，字面意义为映射的字节缓冲区。<br />
01、运用MappedByteBuffer读取文件<br />
假定如今有一个文件，名叫cmower.txt，里面的内容是：<br />
缄默王二，一个有趣的程序员<br />
PS：哎，改不了王婆卖瓜自卖自诩这个臭缺点了，由于文章被盗得都怕了。<br />
这个文件放在/resource目录下，我们能够经过下面的办法获取到它：<br />
ClassLoaderclassLoader=Cmower.class.getClassLoader();<br />
Pathpath=Paths.get(classLoader.getResource(&#8220;cmower.txt&#8221;).getPath());<br />
Path既能够表示一个目录，也能够表示一个文件，就像File那样——当然了，Path是用来取代File的。<br />
然后，从文件中获取一个channel（通道，对磁盘文件的一种笼统）。<br />
FileChannelfileChannel=FileChannel.open(path);<br />
紧接着，调用FileChannel类的map办法从channel中获取MappedByteBuffer，此类扩展了ByteBuffer——提供了一些内存映射文件的根本操作办法。<br />
MappedByteBuffermappedByteBuffer=fileChannel.map(mode,position,size);<br />
略微解释一下map办法的三个参数。<br />
1）mode为文件映射形式，分为三种：<br />
MapMode.READ_ONLY（只读），任何试图修正缓冲区的操作将招致抛出ReadOnlyBufferException异常。<br />
MapMode.READ_WRITE（读/写），任何对缓冲区的更改都会在某个时辰写入文件中。需求留意的是，其他映射同一个文件的程序可能不能立刻看到这些修正，多个程序同时停止文件映射的行为依赖于操作系统。<br />
MapMode.PRIVATE（私有），对缓冲区的更改不会被写入到该文件，任何修正对这个缓冲区来说都是私有的。<br />
2）position为文件映射时的起始位置。<br />
3）size为要映射的区域的大小，必需是非负数，不得大于Integer.MAX_VALUE。<br />
一旦把文件映射到内存缓冲区，我们就能够把里面的数据读入到CharBuffer中并打印出来。详细的代码示例如下。<br />
CharBuffercharBuffer=null;<br />
ClassLoaderclassLoader=Cmower.class.getClassLoader();<br />
Pathpath=Paths.get(classLoader.getResource(&#8220;cmower.txt&#8221;).getPath());<br />
try(FileChannelfileChannel=FileChannel.open(path)){<br />
MappedByteBuffermappedByteBuffer=fileChannel.map(MapMode.READ_ONLY,0,fileChannel.size());<br />
if(mappedByteBuffer!=null){<br />
charBuffer=Charset.forName(&#8220;UTF-8&#8221;).decode(mappedByteBuffer);<br />
}<br />
System.out.println(charBuffer.toString());<br />
}catch(IOExceptione){<br />
e.printStackTrace();<br />
}<br />
由于decode()办法的参数是MappedByteBuffer，这就意味着我们是从内存中而不是磁盘中读入的文件内容，所以速度会十分快。<br />
02、运用MappedByteBuffer写入文件<br />
假定如今要把下面的内容写入到一个文件，名叫cmower1.txt。<br />
缄默王二，《Web全栈开发进阶之路》作者<br />
这个文件还没有创立，方案放在项目的classpath目录下。<br />
Pathpath=Paths.get(&#8220;cmower1.txt&#8221;);<br />
详细位置见下图所示。<br />
然后，创立文件的通道。<br />
FileChannelfileChannel=FileChannel.open(path,StandardOpenOption.READ,StandardOpenOption.WRITE,<br />
StandardOpenOption.TRUNCATE_EXISTING)<br />
依然运用的open办法，不过增加了3个参数，前2个很好了解，表示文件可读（READ）、可写（WRITE）；第3个参数TRUNCATE_EXISTING的意义是假如文件曾经存在，并且文件曾经翻开将要停止WRITE操作，则其长度被截断为0。<br />
紧接着，依然调用FileChannel类的map办法从channel中获取MappedByteBuffer。<br />
MappedByteBuffermappedByteBuffer=fileChannel.map(MapMode.READ_WRITE,0,1024);<br />
这一次，我们把形式调整为MapMode.READ_WRITE，并且指定文件大小为1024，即1KB的大小。然后运用MappedByteBuffer中的put()办法将CharBuffer的内容保管到文件中。详细的代码示例如下。<br />
CharBuffercharBuffer=CharBuffer.wrap(&#8220;缄默王二，《Web全栈开发进阶之路》作者&#8221;);<br />
Pathpath=Paths.get(&#8220;cmower1.txt&#8221;);<br />
try(FileChannelfileChannel=FileChannel.open(path,StandardOpenOption.READ,StandardOpenOption.WRITE,<br />
StandardOpenOption.TRUNCATE_EXISTING)){<br />
MappedByteBuffermappedByteBuffer=fileChannel.map(MapMode.READ_WRITE,0,1024);<br />
if(mappedByteBuffer!=null){<br />
mappedByteBuffer.put(Charset.forName(&#8220;UTF-8&#8221;).encode(charBuffer));<br />
}<br />
}catch(IOExceptione){<br />
e.printStackTrace();<br />
}<br />
能够翻开cmower1.txt查看一下内容，确认预期的内容有没有写入胜利。<br />
03、MappedByteBuffer的遗憾<br />
听说，在Java中运用MappedByteBuffer是一件十分费事并且痛苦的事，主要表现有：<br />
1）一次map的大小最好限制在1.5G左右，反复map会增加虚拟内存回收和重新分配的压力。也就是说，假如文件大小不肯定的话，就不太友好。<br />
2）虚拟内存由操作系统来决议什么时分刷新到磁盘，这个时间不太容易被程序控制。<br />
3）MappedByteBuffer的回收方式比拟诡异。<br />
再次强调，这三种说法都是听说，我暂时才能有限，也不能肯定这种说法的精确性，很遗憾。<br />
04、比拟文件操作的处置时间<br />
嗨，朋友，阅读完以上的内容之后，我想你一定对内存映射文件有了大致的理解。但我置信，假如你是一名担任任的程序员，你一定还想晓得：内存映射文件的读取速度终究有多快。<br />
为了得出结论，我叫了另外三名竞赛的选手：InputStream（普通输入流）、BufferedInputStream（带缓冲的输入流）、RandomAccessFile（随机访问文件）。<br />
读取的对象是加勒比海盗4惊涛怪浪.mkv，大小为1.71G。<br />
1）普通输入流<br />
publicstaticvoidinputStream(Pathfilename){<br />
try(InputStreamis=Files.newInputStream(filename)){<br />
intc;<br />
while((c=is.read())!=-1){<br />
}<br />
}catch(IOExceptione){<br />
e.printStackTrace();<br />
}<br />
}<br />
2）带缓冲的输入流<br />
publicstaticvoidbufferedInputStream(Pathfilename){<br />
try(InputStreamis=newBufferedInputStream(Files.newInputStream(filename))){<br />
intc;<br />
while((c=is.read())!=-1){<br />
}<br />
}catch(IOExceptione){<br />
e.printStackTrace();<br />
}<br />
}<br />
3）随机访问文件<br />
publicstaticvoidrandomAccessFile(Pathfilename){<br />
try(RandomAccessFilerandomAccessFile=newRandomAccessFile(filename.toFile(),&#8221;r&#8221;)){<br />
for(longi=0;i&lt;randomAccessFile.length();i++){<br />
randomAccessFile.seek(i);<br />
}<br />
}catch(IOExceptione){<br />
e.printStackTrace();<br />
}<br />
}<br />
4）内存映射文件<br />
publicstaticvoidmappedFile(Pathfilename){<br />
try(FileChannelfileChannel=FileChannel.open(filename)){<br />
longsize=fileChannel.size();<br />
MappedByteBuffermappedByteBuffer=fileChannel.map(MapMode.READ_ONLY,0,size);<br />
for(inti=0;i&lt;size;i++){<br />
mappedByteBuffer.get(i);<br />
}<br />
}catch(IOExceptione){<br />
e.printStackTrace();<br />
}<br />
}<br />
测试程序也很简单，大致如下：<br />
longstart=System.currentTimeMillis();<br />
bufferedInputStream(Paths.get(&#8220;jialebi.mkv&#8221;));<br />
longend=System.currentTimeMillis();<br />
System.out.println(end-start);<br />
四名选手的结果如下表所示。<br />
办法时间<br />
普通输入流龟速，没有耐烦等出结果<br />
随机访问文件龟速，没有耐烦等下去<br />
带缓冲的输入流29966<br />
内存映射文件914<br />
普通输入流和随机访问文件都慢得要命，真的是龟速，我没有耐烦等候出结果；带缓冲的输入流的表现还不错，但相比内存映射文件就逊色多了。由此得出的结论就是：内存映射文件，上G大文件轻松处置。<br />
05、最后<br />
本篇文章主要引见了Java的内存映射文件，MappedByteBuffer是其灵魂，读取速度快如火箭。另外，一切这些示例和代码片段都能够在GitHub上找到——这是一个Maven项目，所以它很容易导入和运转。</p>


		
										                                </div>
                            </div>
                                                        <div class="wzbq wow slideUp mg-bt30">
                                <span>文章标签：</span>
                                <div class="bqnr">
                                                                                                             <a href="https://www.ciya.cn/tags/website-building/">网站建设</a>
                                                                                                                                                                                                                                                                                                                                                                    </div>
                            </div>
                                                        <div class="xwxq-bot bgf1 wow slideUp">
                                <div class="xwxq-fy clear">
                                    <a class="fl" href="/article/3751.html"><i></i>Java中的锁分类</a>
                                    <a class="fr" href="/article/3749.html"><i></i>Java入门</a>
                                </div>
                                <a class="fhlb" href="#"></a>
                            </div>
                        </div>
                        <div class="fr xwxq-r">
                            <div class="xwxq-tj-page bgf1 mg-bt40 wow slideUp">
                                <div class="xwxq-tj-warp bgfff">
                                    <div class="tjxw-title mg-bt30">
                                        <h3>最新案例</h3><span>LATEST CASES</span>
                                    </div>
                                    <div class="zxal">
                                        <div class="swiper-container">
                                            <div class="swiper-wrapper">
                                                                                                        <div class="imgscale li swiper-slide">
                                                        <a href="https://www.ciya.cn/article/409.html">
                                                            <div class="img100 mg-bt20"><img src="/upload/20211214/20211214103120.jpg" alt="广州呼吸研究院"/></div>
                                                            <p>广州呼吸研究院</p>
                                                        </a>
                                                    </div>
                                                                                                        <div class="imgscale li swiper-slide">
                                                        <a href="https://www.ciya.cn/article/433.html">
                                                            <div class="img100 mg-bt20"><img src="/upload/20211214/20211214102846.jpg" alt="融创集团"/></div>
                                                            <p>融创集团</p>
                                                        </a>
                                                    </div>
                                                                                                        <div class="imgscale li swiper-slide">
                                                        <a href="https://www.ciya.cn/article/268.html">
                                                            <div class="img100 mg-bt20"><img src="/upload/20211214/20211214102923.jpg" alt="粤海集团"/></div>
                                                            <p>粤海集团</p>
                                                        </a>
                                                    </div>
                                                                                                        <div class="imgscale li swiper-slide">
                                                        <a href="https://www.ciya.cn/article/414.html">
                                                            <div class="img100 mg-bt20"><img src="/upload/20211216/20211216115258.jpg" alt="恒大足球学校"/></div>
                                                            <p>恒大足球学校</p>
                                                        </a>
                                                    </div>
                                                                                                        <div class="imgscale li swiper-slide">
                                                        <a href="https://www.ciya.cn/article/477.html">
                                                            <div class="img100 mg-bt20"><img src="/upload/20211214/20211214102958.jpg" alt="侨鑫集团"/></div>
                                                            <p>侨鑫集团</p>
                                                        </a>
                                                    </div>
                                                                                                </div>
                                        </div>
                                        <div class="zxalDot text-center swiperDot"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="xwxq-tj-page bgf1 mg-bt40 wow slideUp">
                                <div class="xwxq-tj-warp bgfff">
                                    <div class="tjxw-title tjxw-title-line mg-bt20">
                                        <h3>热点新闻</h3><span>TOP NEWS</span>
                                    </div>
                                    <ul class="rdxw">
                                                                                <li><a href="https://www.ciya.cn/article/3559.html">1  java heap space(解决方法)</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/1222.html">2  如何在网站后台上传附件</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/1643.html">3  如何在网站后台上传PDF文件</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/1142.html">4  什么是流？</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/3543.html">5  java swing还有人用吗(swing为什么会被淘汰)</a></li>
                                                                            </ul>
                                </div>
                            </div>
                            <div class="xwxq-tj-page bgf1 wow slideUp">
                                <div class="xwxq-tj-warp bgfff">
                                    <div class="tjxw-title tjxw-title-line mg-bt20">
                                        <h3>最新动态</h3><span>NEWS</span>
                                    </div>
                                    <ul class="rdxw">
                                                                                <li><a href="https://www.ciya.cn/article/7318.html">1  商务网站的维护与更新：持续优化，保持竞争力</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/7317.html">2  商务网站的社交媒体营销：扩大品牌影响力，吸引更多潜在客户</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/7316.html">3  商务网站的广告投放：增加收益，提高知名度</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/7315.html">4  商务网站的在线客户服务：提供优质客服，提升用户满意度</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/7314.html">5  商务网站的支付系统集成：安全、便捷的交易方式</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/7313.html">6  商务网站搜索引擎优化（SEO）：提升排名，增加流量</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/7312.html">7  商务网站响应式设计：实现多设备兼容，提升用户体验</a></li>
                                                                                <li><a href="https://www.ciya.cn/article/7311.html">8  商务网站开发：选择合适的编程语言和技术栈</a></li>
                                                                            </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="footerbox">
	<div class="footer">
		<div class="w1700">
			<ul>
				<li>
					<span class="fttitle">思洋 · 广州总部</span>
					<div>
						<p>广州天河区珠江新城富力盈力大厦北塔2706</p>
						<p>020-38013166（网站咨询专线）</p>
					</div>
					<p>400-001-5281 （售后服务热线）</p>
				</li>
				<li>
					<span class="fttitle">思洋 · 深圳</span>
					<div>
						<p>深圳市坂田十二橡树庄园F1-7栋</p>
						<p>Site/ http://www.szciya.com </p>
						<p>E-mail/ itciya@vip.163.com</p>
					</div>
					<p>品牌服务专线：400-001-5281 </p>
				</li>
				<li>
					<span class="fttitle">思洋 · 湖南</span>
					<div>
						<p>长沙市天心区芙蓉中路三段398号新时空大厦5楼</p>
						<p>联系电话/ (+86 0731)88282200</p>
					</div>
					<p>品牌服务专线/ 400-966-8830</p>
				</li>
				<li class="lastli">
					<p class="mt10">旗下运营网站：</p>
					<div class="mt10">
						<img src="/images/ftlogo2.png">
						<img src="/images/gogo.png">
						<img src="/images/ftlogo3.png">
						<img src="/images/ftlogo4.png">
						<img src="/images/ftlogo11.png">
					</div>
				</li>
			</ul>
		</div>
	</div>
	<div class="ft_bottom">
		<div class="w1700">
			<p class="cop">Copyright © 2016 广州思洋文化传播有限公司，保留所有权利。 <a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备09033321号</a>
			</p>
		</div>
	</div>
</div>
<div class="le-box active">
	<div class="t show780">
		<a href="tel:13570966600">
			<img src="/images/ml9-1.png?v=1" alt="" class="sow i">
			<img src="/images/ml9-1.png?v=1" alt="" class="iove i">
		</a>
	</div>
	<div class="t">
		<img src="/images/ml1-1.png?v=1" alt="" class="sow i">
		<img src="/images/ml1-1.png?v=1" alt="" class="iove i">
		<div class="iov">
			<div class="img">
				<img src="/images/qr.jpg" alt="与项目经理交流">
			</div>
			<div class="h">扫描二维码<br>与项目经理交流</div>
		</div>
	</div>
	<div class="t">
		<img src="/images/ml2-1.png?v=1" alt="" class="sow i">
		<img src="/images/ml2-1.png?v=1" alt="" class="iove i">
		<div class="iov">
			<div class="img">
				<img src="/images/qq001.jpg" alt="">
			</div>
			<div class="h">扫描二维码<br>与项目经理交流</div>
		</div>
	</div>
	<!--<div class="t">-->
		<!--<a href="http://wpa.qq.com/msgrd?v=3&amp;uin=1607245872&amp;site=ciya.cn&amp;menu=yes" target="_blank">-->
			<!--<img src="/images/ml2-1.png?v=1" alt="" class="sow i">-->
			<!--<img src="/images/ml2-1.png?v=1" alt="" class="iove i">-->
		<!--</a>-->
	<!--</div>-->
	<div class="t hide780">
		<a href="https://affim.baidu.com/unique_510425/chat?siteId=19536215&userId=510425&siteToken=8914d517c927d8e794148d05e387fb17" target="_blank">
			<img src="/images/ml3-1.png?v=1" alt="" class="sow i">
			<img src="/images/ml3-1.png?v=1" alt="" class="iove i">
		</a>
	</div>
</div>
<script>
	$(window).scroll(function(){
//		if($(window).scrollTop()>200){
//			$(".le-box").addClass("active");
//		}else{
//			$(".le-box").removeClass("active");
//		}
	})
</script>
<div class="wap_fx">
	<a href="tel:13570966600" class="phone"></a>
	<a href="mqqwpa://im/chat?chat_type=wpa&uin=1607245872&version=1&src_type=web&web_src=ciya.cn" target="_blank" class="qq"></a>
	<a href="javascript:;" class="wx2"></a>
	<a class="kef986" style="background:rgba(0,0,0,.6) url(/images/ml3-1.png?v=1) no-repeat center;background-size: cover;border-radius: 4px;" href="https://p.qiao.baidu.com/cps/chat?siteId=18513940&userId=510425&siteToken=e5e1bde478969b43bf99b7703a694c0b" target="_blank"></a>
</div>
<div class="wap-wxcode">
	<div class="middle-box">
		<div class="middle-inner">
			<div class="wap-wxcode-con">
				<img src="/images/ff_ewm.jpg" alt=""/>
				<div class="wap-wxcode-bot"><span class="wxname">ciya68</span><button class="copy-btn" data-clipboard-text="ciya68">点击复制</button></div>
				<div class="gb1002"></div>
			</div>
		</div>
	</div>
</div>
<input id="hide" type="hidden">
<script src="/js/clipboard.min.js"></script>
<script>
	$(function(){
		$(".wx2").click(function(){
			$(".wap-wxcode").show();
		});
		$(".gb1002").click(function(){
			$(".wap-wxcode").hide();
		});
		var copyBtn=new ClipboardJS('.copy-btn');
		copyBtn.on("success",function(e){
			// 复制成功
			// alert(e.text);
			showMessage('已成功复制微信号','success',2000)
			e.clearSelection();
		});
		copyBtn.on("error",function(e){
			//复制失败；
			showMessage('复制微信号失败','error',2000)
			console.log( e.action )
		});
		function showMessage(message,type,time) {
			let str = ''
			switch (type) {
				case 'success':
					str = '<div class="success-message" style="width: 100%;height: 50px;background-color: #030026;font-size:17px;text-align: center;color:#fff;position: fixed;left: 0%;bottom: 0%;line-height: 50px;z-index: 9999">\n' +
							'    <span class="mes-text">'+message+'</span></div>'
					break;
				case 'error':
					str = '<div class="error-message" style="width: 100%;height: 50px;background-color: #030026;font-size:17px;text-align: center;color: #fff;position: fixed;left: 0%;bottom: 0%;line-height: 50px;z-index: 9999">\n' +
							'    <span class="mes-text">'+message+'</span></div>'
			}
			$('body').append(str)
			setTimeout(function () {
				$('.'+type+'-message').remove()
			},time)
		}


		var ua = navigator.userAgent.toLowerCase();
		var isWeixin = ua.indexOf('micromessenger')!= -1;
		if(isWeixin){
			$(".kef986").hide();
		}

	})
</script>
            </div>
        </div>
		<script type="text/javascript" src="/js/trunk.js?v=2"></script>
        <script>
            var zxal=null;
            var len=$(".zxal .swiper-slide").length;
            if(len>1){
                zxal = new Swiper('.zxal .swiper-container',{
                    speed:600,
                    loop:true,
                    autoplay : 5000,
                    autoplayDisableOnInteraction : false,
                    pagination : '.zxalDot',
                    paginationClickable :true,
                })
            }else{
                $(".zxalDot").hide();
            }
        </script>
	</body>
</html>

