1.阻塞模式实例  

  NIOUtil类,用来通过SOcket获取BufferedReader和PrintWriter。

package IO;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket; public class NIOUtil {
public static PrintWriter getPrintWriter(Socket socket) throws IOException {
OutputStream outputStream = socket.getOutputStream();
return new PrintWriter(outputStream, true);
} public static BufferedReader getBufferedReader(Socket socket)
throws IOException {
InputStream inputStream = socket.getInputStream();
return new BufferedReader(new InputStreamReader(inputStream));
}
}

  使用ServerSocketChannel创建阻塞服务器端程序:

package IO;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; public class BlockingNIOServer {
private int port = 8000;
private ServerSocketChannel serverSocketChannel = null;
private ExecutorService executorService = null;
private static int DEFAULT_POOI_SIZE = 4; public BlockingNIOServer() throws IOException {
super();
this.executorService = Executors.newFixedThreadPool(DEFAULT_POOI_SIZE
* Runtime.getRuntime().availableProcessors());
this.serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().setReuseAddress(true);
serverSocketChannel.socket().bind(new InetSocketAddress(port));
this.executorService = executorService;
} public void service() {
while (true) {
SocketChannel channel = null;
try {
channel = serverSocketChannel.accept();
executorService.execute(new Handler(channel));
} catch (Exception e) {
e.printStackTrace();
}
}
} public static void main(String[] args) throws Exception {
new BlockingNIOServer().service();
} private class Handler implements Runnable {
private SocketChannel channel;
public Handler(SocketChannel channel) {
super();
this.channel = channel;
} @Override
public void run() {
handler(channel);
} public void handler(SocketChannel channel) {
Socket socket = null;
try {
socket = channel.socket();
System.out.println("接收到来自:" + socket.getInetAddress() + " 端口:"
+ socket.getPort() + "的请求");
BufferedReader bufferedReader = NIOUtil
.getBufferedReader(socket);
PrintWriter printWriter = NIOUtil.getPrintWriter(socket);
String msg = null; while ((msg = bufferedReader.readLine()) != null) {
System.out.println(msg);
printWriter.println(Echo(msg));
if ("bye".equalsIgnoreCase(msg))
break;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (channel != null) {
try {
channel.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} } private String Echo(String msg) {
return "ECHO:" + msg;
}
}
}

  使用SocketChannel创建阻塞Socket客户端:

package IO;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; public class BlockingNIOServer {
private int port = 8000;
private ServerSocketChannel serverSocketChannel = null;
private ExecutorService executorService = null;
private static int DEFAULT_POOI_SIZE = 4; public BlockingNIOServer() throws IOException {
super();
this.executorService = Executors.newFixedThreadPool(DEFAULT_POOI_SIZE
* Runtime.getRuntime().availableProcessors());
this.serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().setReuseAddress(true);
serverSocketChannel.socket().bind(new InetSocketAddress(port));
this.executorService = executorService;
} public void service() {
while (true) {
SocketChannel channel = null;
try {
channel = serverSocketChannel.accept();
executorService.execute(new Handler(channel));
} catch (Exception e) {
e.printStackTrace();
}
}
} public static void main(String[] args) throws Exception {
new BlockingNIOServer().service();
} private class Handler implements Runnable {
private SocketChannel channel;
public Handler(SocketChannel channel) {
super();
this.channel = channel;
} @Override
public void run() {
handler(channel);
} public void handler(SocketChannel channel) {
Socket socket = null;
try {
socket = channel.socket();
System.out.println("接收到来自:" + socket.getInetAddress() + " 端口:"
+ socket.getPort() + "的请求");
BufferedReader bufferedReader = NIOUtil
.getBufferedReader(socket);
PrintWriter printWriter = NIOUtil.getPrintWriter(socket);
String msg = null; while ((msg = bufferedReader.readLine()) != null) {
System.out.println(msg);
printWriter.println(Echo(msg));
if ("bye".equalsIgnoreCase(msg))
break;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (channel != null) {
try {
channel.close();
} catch (IOException e) {
e.printStackTrace();
}
}
} } private String Echo(String msg) {
return "ECHO:" + msg;
}
}
}

2.非阻塞模式实例

  Charset类,主要用于decode()和encode()

package IO;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset; public class CharSetUtil {
public static String decode(ByteBuffer buffer, String charsetName) {
Charset charset = Charset.forName(charsetName);
CharBuffer msg = charset.decode(buffer);
return msg.toString();
} public static ByteBuffer encode(String msg, String charsetName) {
Charset charset = Charset.forName(charsetName);
ByteBuffer byteBuffer = charset.encode(msg);
return byteBuffer;
}
}

  非阻塞的服务器端

package IO;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; public class NoBlockingServer {
private int port = 8000;
private ServerSocketChannel serverSocketChannel = null;
private Selector selector = null; public NoBlockingServer() throws IOException {
super();
selector = Selector.open();
this.serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().setReuseAddress(true);
serverSocketChannel.configureBlocking(false);//设置为非阻塞
serverSocketChannel.socket().bind(new InetSocketAddress(port));
System.out.println("服务器启动成功");
} public void service() throws IOException {
//给serverSocketChannel注册OP_ACCEPT事件
serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
//注意selector.select()将会阻塞
while (selector.select() > 0) {
Set<SelectionKey> selectionKeys = selector.selectedKeys();
Iterator iterator = selectionKeys.iterator();
while (iterator.hasNext()) {
SelectionKey selectionKey = null;
try {
selectionKey = (SelectionKey) iterator.next();
iterator.remove(); if (selectionKey.isAcceptable()) {
dealWithAcceptable(selectionKey);
}
if (selectionKey.isReadable()) {
dealWithReadable(selectionKey);
}
if (selectionKey.isWritable()) {
dealWithWritable(selectionKey);
}
} catch (Exception e) {
if (selectionKey != null) {
selectionKey.cancel();
selectionKey.channel().close();
}
}
}
}
} private void dealWithAcceptable(SelectionKey selectionKey)
throws IOException {
ServerSocketChannel serverSocketChannel = (ServerSocketChannel) selectionKey
.channel();
SocketChannel socketChannel = serverSocketChannel.accept();
System.out.println("接收到来自:" + socketChannel.socket().getInetAddress()
+ " 端口" + socketChannel.socket().getPort() + "的请求");
socketChannel.configureBlocking(false);
ByteBuffer buffer = ByteBuffer.allocate(1024);
socketChannel.register(selectionKey.selector(), SelectionKey.OP_READ
| SelectionKey.OP_WRITE, buffer);
} private void dealWithReadable(SelectionKey selectionKey) throws IOException{
ByteBuffer buffer=(ByteBuffer) selectionKey.attachment();
SocketChannel channel=(SocketChannel) selectionKey.channel();
ByteBuffer readBuffer=ByteBuffer.allocate(32);
channel.read(readBuffer);
readBuffer.flip(); buffer.limit(buffer.capacity());
buffer.put(readBuffer);
} private void dealWithWritable(SelectionKey selectionKey) throws IOException{
ByteBuffer buffer=(ByteBuffer) selectionKey.attachment();
SocketChannel channel=(SocketChannel) selectionKey.channel();
buffer.flip(); String msg=CharSetUtil.decode(buffer, "UTF-8"); if(msg.indexOf("\r\n")==-1){
return;
} String outPutData=msg.substring(0, msg.indexOf("\n")+1);
System.out.println("接收来自客户端的数据:"+outPutData); ByteBuffer outbyteBuffer=CharSetUtil.encode("echo:"+outPutData, "UTF-8");
while (outbyteBuffer.hasRemaining()) {
channel.write(outbyteBuffer);
} ByteBuffer tmp=CharSetUtil.encode(outPutData, "UTF-8");
buffer.position(tmp.limit());
buffer.compact();
if("bye\r\n".equalsIgnoreCase(outPutData)){
selectionKey.cancel();
channel.close();
System.out.println("关闭与客户端的连接");
}
} public static void main(String[] args) throws Exception {
new NoBlockingServer().service();
}
}

  非阻塞的客户端

package IO;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Set; public class NoBlockingClient {
private SocketChannel channel = null;
private ByteBuffer send = ByteBuffer.allocate(1024);
private ByteBuffer rece = ByteBuffer.allocate(1024);
private Selector selector; public NoBlockingClient() throws IOException {
super();
channel = SocketChannel.open();
channel.socket().connect(new InetSocketAddress("localhost", 8000));
channel.configureBlocking(false); System.out.println("与服务器建立连接成功");
selector = Selector.open();
} public void talk() throws IOException {
channel.register(selector, SelectionKey.OP_READ|SelectionKey.OP_WRITE);
while (selector.select() > 0) {
Set<SelectionKey> selectionKeys = selector.selectedKeys();
Iterator iterator = selectionKeys.iterator();
while (iterator.hasNext()) {
SelectionKey selectionKey = null;
try {
selectionKey = (SelectionKey) iterator.next();
iterator.remove(); if (selectionKey.isReadable()) {
dealWithReadable(selectionKey);
}
if (selectionKey.isWritable()) {
dealWithWritable(selectionKey);
}
} catch (Exception e) {
if (selectionKey != null) {
selectionKey.cancel();
try {
selectionKey.channel().close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
}
} private void receFromUser() throws IOException{
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
String msg=null;
while ((msg=bufferedReader.readLine())!=null) {
synchronized (send) {
send.put(CharSetUtil.encode(msg+"\r\n", "UTF-8"));
}
if ("bye".equalsIgnoreCase(msg)) {
break;
}
}
} private void dealWithWritable(SelectionKey selectionKey) throws IOException{
SocketChannel channel=(SocketChannel) selectionKey.channel();
synchronized (send) {
send.flip();
channel.write(send);
send.compact();
}
} private void dealWithReadable(SelectionKey selectionKey) throws IOException{
SocketChannel channel=(SocketChannel) selectionKey.channel();
channel.read(rece);
rece.flip();
String msg=CharSetUtil.decode(rece, "UTF-8"); if(msg.indexOf("\r\n")==-1){
return;
} String outPutData=msg.substring(0, msg.indexOf("\n")+1);
System.out.println(outPutData); if("echo:bye\r\n".equalsIgnoreCase(outPutData)){
selectionKey.cancel();
channel.close();
selector.close();
System.out.println("关闭与客户端的连接");
} ByteBuffer tmp=CharSetUtil.encode(outPutData, "UTF-8");
rece.position(tmp.limit());
rece.compact();
} public static void main(String[] args) throws IOException {
System.out.println(System.getProperty("file.encoding"));
final NoBlockingClient noBlockingClient=new NoBlockingClient();
Thread thread=new Thread(){
public void run() {
try {
noBlockingClient.receFromUser();
} catch (IOException e) {
e.printStackTrace();
}
};
}; thread.start();
noBlockingClient.talk();
}
}

3.阻塞和非阻塞编程实例

  服务器端使用阻塞和非阻塞模式,f负责接收客户端连接的线程按照阻塞模式工作,负责接收和发送数据的线程按照非阻塞模式工作。

package IO;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Set; public class NOBlockingAndBolckingServer {
private int port = 8000;
private ServerSocketChannel serverSocketChannel = null;
private Selector selector = null;
private Object gate = new Object(); public NOBlockingAndBolckingServer() throws IOException {
super();
selector = Selector.open();
this.serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.socket().bind(new InetSocketAddress(port));
System.out.println("服务器启动成功");
} public void accept() {
for (;;) {
try {
SocketChannel socketChannel = serverSocketChannel.accept();
System.out.println("接收到来自:"
+ socketChannel.socket().getInetAddress() + " 端口"
+ socketChannel.socket().getPort() + "的请求");
socketChannel.configureBlocking(false); synchronized (gate) {
selector.wakeup();
socketChannel.register(selector, SelectionKey.OP_READ
| SelectionKey.OP_WRITE);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} public void service() throws IOException {
// 给serverSocketChannel注册OP_ACCEPT事件
for (;;) {
synchronized (gate) {
int n = selector.select();
if (n == 0)
continue;
Set<SelectionKey> selectionKeys = selector.selectedKeys();
Iterator iterator = selectionKeys.iterator();
while (iterator.hasNext()) {
SelectionKey selectionKey = null;
try {
selectionKey = (SelectionKey) iterator.next();
iterator.remove(); if (selectionKey.isReadable()) {
dealWithReadable(selectionKey);
}
if (selectionKey.isWritable()) {
dealWithWritable(selectionKey);
}
} catch (Exception e) {
if (selectionKey != null) {
selectionKey.cancel();
selectionKey.channel().close();
}
}
}
}
}
} private void dealWithReadable(SelectionKey selectionKey) throws IOException {
ByteBuffer buffer = (ByteBuffer) selectionKey.attachment();
SocketChannel channel = (SocketChannel) selectionKey.channel();
ByteBuffer readBuffer = ByteBuffer.allocate(32);
channel.read(readBuffer);
readBuffer.flip(); buffer.limit(buffer.capacity());
buffer.put(readBuffer);
} private void dealWithWritable(SelectionKey selectionKey) throws IOException {
ByteBuffer buffer = (ByteBuffer) selectionKey.attachment();
SocketChannel channel = (SocketChannel) selectionKey.channel();
buffer.flip(); String msg = CharSetUtil.decode(buffer, "UTF-8"); if (msg.indexOf("\r\n") == -1) {
return;
} String outPutData = msg.substring(0, msg.indexOf("\n") + 1);
System.out.println("接收来自客户端的数据:" + outPutData); ByteBuffer outbyteBuffer = CharSetUtil.encode("echo:" + outPutData,
"UTF-8");
while (outbyteBuffer.hasRemaining()) {
channel.write(outbyteBuffer);
} ByteBuffer tmp = CharSetUtil.encode(outPutData, "UTF-8");
buffer.position(tmp.limit());
buffer.compact();
if ("bye\r\n".equalsIgnoreCase(outPutData)) {
selectionKey.cancel();
channel.close();
System.out.println("关闭与客户端的连接");
}
} public static void main(String[] args) throws Exception {
final NOBlockingAndBolckingServer server=new NOBlockingAndBolckingServer();
Thread thread=new Thread(){
public void run() {
server.accept();
};
};
thread.start();
server.service();
}
}

  客户端和服务器端创建多个连接。

package IO;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.LinkedList; class Target { // 表示一项任务
InetSocketAddress address;
SocketChannel channel;
Exception failure;
long connectStart; // 开始连接时的时间
long connectFinish = 0; // 连接成功时的时间
boolean shown = false; // 该任务是否已经打印 Target(String host) {
try {
address = new InetSocketAddress(InetAddress.getByName(host), 80);
} catch (IOException x) {
failure = x;
}
} void show() { // 打印任务执行的结果
String result;
if (connectFinish != 0)
result = Long.toString(connectFinish - connectStart) + "ms";
else if (failure != null)
result = failure.toString();
else
result = "Timed out";
System.out.println(address + " : " + result);
shown = true;
}
} public class PingClient {
private Selector selector;
// 存放用户新提交的任务
private LinkedList targets = new LinkedList();
// 存放已经完成的需要打印的任务
private LinkedList finishedTargets = new LinkedList(); public PingClient() throws IOException {
selector = Selector.open();
Connector connector = new Connector();
Printer printer = new Printer();
connector.start();
printer.start();
receiveTarget();
} public static void main(String args[]) throws IOException {
new PingClient();
} public void addTarget(Target target) {
// 向targets队列中加入一个任务
SocketChannel socketChannel = null;
try {
socketChannel = SocketChannel.open();
socketChannel.configureBlocking(false);
socketChannel.connect(target.address); target.channel = socketChannel;
target.connectStart = System.currentTimeMillis(); synchronized (targets) {
targets.add(target);
}
selector.wakeup();
} catch (Exception x) {
if (socketChannel != null) {
try {
socketChannel.close();
} catch (IOException xx) {
}
}
target.failure = x;
addFinishedTarget(target);
}
} public void addFinishedTarget(Target target) {
// 向finishedTargets队列中加入一个任务
synchronized (finishedTargets) {
finishedTargets.notify();
finishedTargets.add(target);
}
} public void printFinishedTargets() {
// 打印finisedTargets队列中的任务
try {
for (;;) {
Target target = null;
synchronized (finishedTargets) {
while (finishedTargets.size() == 0)
finishedTargets.wait();
target = (Target) finishedTargets.removeFirst();
}
target.show();
}
} catch (InterruptedException x) {
return;
}
} public void registerTargets() {
// 取出targets队列中的任务,向Selector注册连接就绪事件
synchronized (targets) {
while (targets.size() > 0) {
Target target = (Target) targets.removeFirst(); try {
target.channel.register(selector, SelectionKey.OP_CONNECT,
target);
} catch (IOException x) {
try {
target.channel.close();
} catch (IOException e) {
e.printStackTrace();
}
target.failure = x;
addFinishedTarget(target);
}
}
}
} public void processSelectedKeys() throws IOException {
// 处理连接就绪事件
for (Iterator it = selector.selectedKeys().iterator(); it.hasNext();) {
SelectionKey selectionKey = (SelectionKey) it.next();
it.remove(); Target target = (Target) selectionKey.attachment();
SocketChannel socketChannel = (SocketChannel) selectionKey
.channel(); try {
if (socketChannel.finishConnect()) {
selectionKey.cancel();
target.connectFinish = System.currentTimeMillis();
socketChannel.close();
addFinishedTarget(target);
}
} catch (IOException x) {
socketChannel.close();
target.failure = x;
addFinishedTarget(target);
}
}
} //接收用户输入的地址,向targets队列中加入任务
public void receiveTarget() {
try {
BufferedReader localReader = new BufferedReader(
new InputStreamReader(System.in));
String msg = null;
while ((msg = localReader.readLine()) != null) {
if (!msg.equals("bye")) {
Target target = new Target(msg);
addTarget(target);
} else {
shutdown = true;
selector.wakeup();
break;
}
}
} catch (IOException e) {
e.printStackTrace();
}
} boolean shutdown = false; public class Printer extends Thread {
public Printer() {
setDaemon(true);
} public void run() {
printFinishedTargets();
}
} public class Connector extends Thread {
public void run() {
while (!shutdown) {
try {
registerTargets();
if (selector.select() > 0) {
processSelectedKeys();
}
} catch (Exception e) {
e.printStackTrace();
}
}
try {
selector.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

NIO Socket编程实例的更多相关文章

  1. Java NIO Socket编程实例

    各I/O模型优缺点 BIO通信模型 BIO主要的问题在于每当有一个新的客户端请求接入时,服务端必须创建一个新的线程处理新接入的客户端链路,一个线程只能处理一个客户端连接 线程池I/O编程 假如所有可用 ...

  2. linux下socket编程实例

    linux下socket编程实例一.基本socket函数Linux系统是通过提供套接字(socket)来进行网络编程的.网络的socket数据传输是一种特殊的I/O,socket也是一种文件描述符.s ...

  3. 【转】netlink socket编程实例

    [转]netlink socket编程实例 转自:http://blog.chinaunix.net/uid-14753126-id-2983915.html 关于Netlink IPC方式的介绍,请 ...

  4. TCP/UDP套接字 java socket编程实例

    网络协议七层结构: 什么是Socket? socket(套接字)是两个程序之间通过双向信道进行数据交换的端,可以理解为接口.使用socket编程也称为网络编程,socket只是接口并不是网络通信协议. ...

  5. [转] - linux下socket编程实例

    一.基本socket函数Linux系统是通过提供套接字(socket)来进行网络编程的.网络的socket数据传输是一种特殊的I/O,socket也是一种文件描述符.socket也有一个类似于打开文件 ...

  6. C++/C socket编程实例

    目录 基于TCP的socket编程 服务器代码 客户端代码 运行结果 基于UDP的socket编程 服务器代码 客户端代码 运行结果 基于TCP的socket编程 服务器代码 服务器端代码如下 //T ...

  7. java socket编程实例代码

    1.所谓socket通常也称作"套接字",用于描述IP地址和端口,是一个通信链的句柄.应用程序通常通过"套接字"向网络发出请求或者应答网络请求. 两性话题 两性 ...

  8. 网络编程之socket编程实例

    简单实例1 server.c #include <stdio.h> #include <string.h> #include <stdlib.h> #include ...

  9. Linux下的C++ socket编程实例

    阅读目录 基本的局域网聊天 客户端服务端双向异步聊天源码 局域网内服务端和有限个客户端聊天源码 完美异步聊天服务端和客户端源码 C++定时器 select异步代码 pthead多线程 服务端: 服务器 ...

随机推荐

  1. Google永远不可能回到国内,只能是回忆

    今天早上在微博上无意看 [谷歌翻译App在大陆地区恢复无障碍使用]这篇文章,不知不觉就点进去看一下,内心还是比较兴奋,为什么兴奋说不清楚.或许我们是真的喜欢Google的产品. 回想2010年Goog ...

  2. 老李分享:jvm垃圾回收

    老李分享:jvm垃圾回收   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:908821478 ...

  3. body全屏

    html, body { min-height: 100%; }

  4. .NET遇上Docker - Harbor的安装与基本使用

    Harbor是一个开源企业级Docker注册中心,可以用于搭建私有的Docker Image仓库.可以实现权限控制等. 安装Harbor 首先,需要安装Docker和Docker Compose,参考 ...

  5. 我的iOS博客旅行开始了,欢迎光临!

    期待您的关注!

  6. javascript数组常用方法详解

    1,splice().   array.splice(index,many,list1,list2....)  参数1.index位置 负数为从结尾处算,倒数第一为-1:参数2,many要删除的项目, ...

  7. 【CSS】如何用css做一个爱心

    摘要:HTML的标签都比较简单,入门非常的迅速,但是CSS是一个需要我们深度挖掘的东西,里面的很多样式属性掌握几个常用的便可以实现很好看的效果,下面我便教大家如何用CSS做一个爱心. 前期预备知识: ...

  8. IntelliJ IDEA应用[一]下载与安装

    一.IntelliJ IDEA 12.1.6的下载 IntelliJ IDEA的官方下载网站:http://www.jetbrains.com/idea/download/

  9. 利用 Forcing InnoDB Recovery 特性解决 MySQL 重启失败的问题

    小明同学在本机上安装了 MySQL 5.7.17 配合项目进行开发,并且已经有了一部分重要数据.某天小明在开发的时候,需要出去一趟就直接把电脑关掉了,没有让 MySQL 正常关闭,重启 MySQL 的 ...

  10. 对百度WebUploader的二次封装,精简前端代码之图片预览上传(两句代码搞定上传)

    前言 本篇文章上一篇: 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传) 此篇是在上面的基础上扩展出来专门上传图片的控件封装. 首先我们看看效果: 正文 使用方式同 ...