Java_io体系之PipedWriter、PipedReader简介、走进源码及示例——14

——管道字符输出流、必须建立在管道输入流之上、所以先介绍管道字符输出流。可以先看示例或者总结、总结写的有点Q、不喜可无视、有误的地方指出则不胜感激。

一:PipedWriter


1、类功能简介:


管道字符输出流、用于将当前线程的指定字符写入到与此线程对应的管道字符输入流中去、所以PipedReader(pr)、PipedWriter(pw)必须配套使用、缺一不可。管道字符输出流的本质就是调用pr中的方法将字符或者字符数组写入到pr中、这一点是与众不同的地方。所以pw中的方法很少也很简单、主要就是负责将传入的pr与本身绑定、配对使用、然后就是调用绑定的pr的写入方法、将字符或者字符数组写入到pr的缓存字符数组中。

2、PipedWriter  API简介:


A:关键字


  1. private PipedReader sink; 与此PipedWriter绑定的PipedReader
  2.  
  3. private boolean closed = false; 标示此流是否关闭。

B:构造方法


  1. PipedWriter(PipedReader snk) 根据传入的PipedReader构造pw、并将pr与此pw绑定
  2.  
  3. PipedWriter() 创建一个pw、在使用之前必须与一个pr绑定

C:一般方法


  1. synchronized void connect(PipedReader snk) 将此pw与一个pr绑定
  2.  
  3. void close() 关闭此流。
  4.  
  5. synchronized void connect(PipedReader snk) 将此pw与一个pr绑定
  6.  
  7. synchronized void flush() flush此流、唤醒pr中所有等待的方法。
  8.  
  9. void write(int c) 将一个整数写入到与此pw绑定的pr的缓存字符数组buf中去
  10.  
  11. void write(char cbuf[], int off, int len) cbuf的一部分写入prbuf中去

3、源码分析


  1. package com.chy.io.original.code;
  2.  
  3. import java.io.IOException;
  4.  
  5. public class PipedWriter extends Writer {
  6.  
  7. //与此PipedWriter绑定的PipedReader
  8. private PipedReader sink;
  9.  
  10. //标示此流是否关闭。
  11. private boolean closed = false;
  12.  
  13. /**
  14. * 根据传入的PipedReader构造pw、并将pr与此pw绑定
  15. */
  16. public PipedWriter(PipedReader snk) throws IOException {
  17. connect(snk);
  18. }
  19.  
  20. /**
  21. * 创建一个pw、在使用之前必须与一个pr绑定
  22. */
  23. public PipedWriter() {
  24. }
  25.  
  26. /**
  27. * 将此pw与一个pr绑定
  28. */
  29. public synchronized void connect(PipedReader snk) throws IOException {
  30. if (snk == null) {
  31. throw new NullPointerException();
  32. } else if (sink != null || snk.connected) {
  33. throw new IOException("Already connected");
  34. } else if (snk.closedByReader || closed) {
  35. throw new IOException("Pipe closed");
  36. }
  37.  
  38. sink = snk;
  39. snk.in = -1;
  40. snk.out = 0;
  41. snk.connected = true;
  42. }
  43.  
  44. /**
  45. * 将一个整数写入到与此pw绑定的pr的缓存字符数组buf中去
  46. */
  47. public void write(int c) throws IOException {
  48. if (sink == null) {
  49. throw new IOException("Pipe not connected");
  50. }
  51. sink.receive(c);
  52. }
  53.  
  54. /**
  55. * 将cbuf的一部分写入pr的buf中去
  56. */
  57. public void write(char cbuf[], int off, int len) throws IOException {
  58. if (sink == null) {
  59. throw new IOException("Pipe not connected");
  60. } else if ((off | len | (off + len) | (cbuf.length - (off + len))) < 0) {
  61. throw new IndexOutOfBoundsException();
  62. }
  63. sink.receive(cbuf, off, len);
  64. }
  65.  
  66. /**
  67. * flush此流、唤醒pr中所有等待的方法。
  68. */
  69. public synchronized void flush() throws IOException {
  70. if (sink != null) {
  71. if (sink.closedByReader || closed) {
  72. throw new IOException("Pipe closed");
  73. }
  74. synchronized (sink) {
  75. sink.notifyAll();
  76. }
  77. }
  78. }
  79.  
  80. /**
  81. * 关闭此流。
  82. */
  83. public void close() throws IOException {
  84. closed = true;
  85. if (sink != null) {
  86. sink.receivedLast();
  87. }
  88. }
  89. }

4、实例演示:


因为PipedWriter必须与PipedReader结合使用、所以将两者的示例放在一起。

二:PipedReader


1、类功能简介:


管道字符输入流、用于读取对应绑定的管道字符输出流写入其内置字符缓存数组buffer中的字符、借此来实现线程之间的通信、pr中专门有两个方法供pw调用、receive(char c)、receive(char[] b, int off, intlen)、使得pw可以将字符或者字符数组写入pr的buffer中、

 

2、PipedReader  API简介:


A:关键字


  1. boolean closedByWriter = false; 标记PipedWriter是否关闭
  2.  
  3. boolean closedByReader = false; 标记PipedReader是否关闭
  4.  
  5. boolean connected = false; 标记PipedWriter与标记PipedReader是否关闭的连接是否关闭
  6.  
  7. Thread readSide; 拥有PipedReader的线程
  8.  
  9. Thread writeSide; 拥有PipedWriter的线程
  10.  
  11. private static final int DEFAULT_PIPE_SIZE = 1024; 用于循环存放PipedWriter写入的字符数组的默认大小
  12.  
  13. char buffer[]; 用于循环存放PipedWriter写入的字符数组
  14.  
  15. int in = -1; buf中下一个存放PipedWriter调用此PipedReaderreceive(int c)时、cbuf中存放的位置的下标。此为初始状态、即buf中没有字符
  16.  
  17. int out = 0; buf中下一个被读取的字符的下标

B:构造方法


  1. PipedReader(PipedWriter src) 使用默认的buf的大小和传入的pw构造pr
  2.  
  3. PipedReader(PipedWriter src, int pipeSize) 使用指定的buf的大小和传入的pw构造pr
  4.  
  5. PipedReader() 使用默认大小构造pr
  6.  
  7. PipedReader(int pipeSize) 使用指定大小构造pr

C:一般方法


  1. void close() 清空buf中数据、关闭此流。
  2.  
  3. void connect(PipedWriter src) 调用与此流绑定的pwconnect方法、将此流与对应的pw绑定
  4.  
  5. synchronized boolean ready() 查看此流是否可读
  6.  
  7. synchronized int read() buf中读取一个字符、以整数形式返回
  8.  
  9. synchronized int read(char cbuf[], int off, int len) buf中读取一部分字符到cbuf中。
  10.  
  11. synchronized void receive(int c) pw调用此流的此方法、向prbuf以整数形式中写入一个字符。
  12.  
  13. synchronized void receive(char c[], int off, int len) c中一部分字符写入到buf中。
  14.  
  15. synchronized void receivedLast() 提醒所有等待的线程、已经接收到了最后一个字符。

3、源码分析


  1. package com.chy.io.original.code;
  2.  
  3. import java.io.IOException;
  4.  
  5. public class PipedReader extends Reader {
  6. boolean closedByWriter = false;
  7. boolean closedByReader = false;
  8. boolean connected = false;
  9.  
  10. Thread readSide;
  11. Thread writeSide;
  12.  
  13. /**
  14. * 用于循环存放PipedWriter写入的字符数组的默认大小
  15. */
  16. private static final int DEFAULT_PIPE_SIZE = 1024;
  17.  
  18. /**
  19. * 用于循环存放PipedWriter写入的字符数组
  20. */
  21. char buffer[];
  22.  
  23. /**
  24. * buf中下一个存放PipedWriter调用此PipedReader的receive(int c)时、c在buf中存放的位置的下标。
  25. * in为-1时、说明buf中没有可读取字符、in=out时已经存满了。
  26. */
  27. int in = -1;
  28.  
  29. /**
  30. * buf中下一个被读取的字符的下标
  31. */
  32. int out = 0;
  33.  
  34. /**
  35. * 使用默认的buf的大小和传入的pw构造pr
  36. */
  37. public PipedReader(PipedWriter src) throws IOException {
  38. this(src, DEFAULT_PIPE_SIZE);
  39. }
  40.  
  41. /**
  42. * 使用指定的buf的大小和传入的pw构造pr
  43. */
  44. public PipedReader(PipedWriter src, int pipeSize) throws IOException {
  45. initPipe(pipeSize);
  46. connect(src);
  47. }
  48.  
  49. /**
  50. * 使用默认大小构造pr
  51. */
  52. public PipedReader() {
  53. initPipe(DEFAULT_PIPE_SIZE);
  54. }
  55.  
  56. /**
  57. * 使用指定大小构造pr
  58. */
  59. public PipedReader(int pipeSize) {
  60. initPipe(pipeSize);
  61. }
  62.  
  63. //初始化buf大小
  64. private void initPipe(int pipeSize) {
  65. if (pipeSize <= 0) {
  66. throw new IllegalArgumentException("Pipe size <= 0");
  67. }
  68. buffer = new char[pipeSize];
  69. }
  70.  
  71. /**
  72. * 调用与此流绑定的pw的connect方法、将此流与对应的pw绑定
  73. */
  74. public void connect(PipedWriter src) throws IOException {
  75. src.connect(this);
  76. }
  77.  
  78. /**
  79. * pw调用此流的此方法、向pr的buf以整数形式中写入一个字符。
  80. */
  81. synchronized void receive(int c) throws IOException {
  82. if (!connected) {
  83. throw new IOException("Pipe not connected");
  84. } else if (closedByWriter || closedByReader) {
  85. throw new IOException("Pipe closed");
  86. } else if (readSide != null && !readSide.isAlive()) {
  87. throw new IOException("Read end dead");
  88. }
  89.  
  90. writeSide = Thread.currentThread();
  91. while (in == out) {
  92. if ((readSide != null) && !readSide.isAlive()) {
  93. throw new IOException("Pipe broken");
  94. }
  95. //buf中写入的被读取完、唤醒所有此对象监控的线程其他方法、如果一秒钟之后还是满值、则再次唤醒其他方法、直到buf中被读取。
  96. notifyAll();
  97. try {
  98. wait(1000);
  99. } catch (InterruptedException ex) {
  100. throw new java.io.InterruptedIOException();
  101. }
  102. }
  103. //buf中存放第一个字符时、将字符在buf中存放位置的下标in初始化为0、读取的下标也初始化为0、准备接受写入的第一个字符。
  104. if (in < 0) {
  105. in = 0;
  106. out = 0;
  107. }
  108. buffer[in++] = (char) c;
  109. //如果buf中放满了、则再从头开始存放。
  110. if (in >= buffer.length) {
  111. in = 0;
  112. }
  113. }
  114.  
  115. /**
  116. * 将c中一部分字符写入到buf中。
  117. */
  118. synchronized void receive(char c[], int off, int len) throws IOException {
  119. while (--len >= 0) {
  120. receive(c[off++]);
  121. }
  122. }
  123.  
  124. /**
  125. * 提醒所有等待的线程、已经接收到了最后一个字符、PipedWriter已关闭。用于PipedWriter的close()方法.
  126. */
  127. synchronized void receivedLast() {
  128. closedByWriter = true;
  129. notifyAll();
  130. }
  131.  
  132. /**
  133. * 从buf中读取一个字符、以整数形式返回
  134. */
  135. public synchronized int read() throws IOException {
  136. if (!connected) {
  137. throw new IOException("Pipe not connected");
  138. } else if (closedByReader) {
  139. throw new IOException("Pipe closed");
  140. } else if (writeSide != null && !writeSide.isAlive() && !closedByWriter && (in < 0)) {
  141. throw new IOException("Write end dead");
  142. }
  143.  
  144. readSide = Thread.currentThread();
  145. int trials = 2;
  146. while (in < 0) {
  147. if (closedByWriter) {
  148. /* closed by writer, return EOF */
  149. return -1;
  150. }
  151. if ((writeSide != null) && (!writeSide.isAlive()) && (--trials < 0)) {
  152. throw new IOException("Pipe broken");
  153. }
  154. /* might be a writer waiting */
  155. notifyAll();
  156. try {
  157. wait(1000);
  158. } catch (InterruptedException ex) {
  159. throw new java.io.InterruptedIOException();
  160. }
  161. }
  162. int ret = buffer[out++];
  163. if (out >= buffer.length) {
  164. out = 0;
  165. }
  166. if (in == out) {
  167. /* now empty */
  168. in = -1;
  169. }
  170. return ret;
  171. }
  172.  
  173. /**
  174. * 将buf中读取一部分字符到cbuf中。
  175. */
  176. public synchronized int read(char cbuf[], int off, int len) throws IOException {
  177. if (!connected) {
  178. throw new IOException("Pipe not connected");
  179. } else if (closedByReader) {
  180. throw new IOException("Pipe closed");
  181. } else if (writeSide != null && !writeSide.isAlive() && !closedByWriter && (in < 0)) {
  182. throw new IOException("Write end dead");
  183. }
  184.  
  185. if ((off < 0) || (off > cbuf.length) || (len < 0) ||
  186. ((off + len) > cbuf.length) || ((off + len) < 0)) {
  187. throw new IndexOutOfBoundsException();
  188. } else if (len == 0) {
  189. return 0;
  190. }
  191.  
  192. /* possibly wait on the first character */
  193. int c = read();
  194. if (c < 0) {
  195. return -1;
  196. }
  197. cbuf[off] = (char)c;
  198. int rlen = 1;
  199. while ((in >= 0) && (--len > 0)) {
  200. cbuf[off + rlen] = buffer[out++];
  201. rlen++;
  202. //如果读取的下一个字符下标大于buffer的size、则重置out、从新开始从第一个开始读取。
  203. if (out >= buffer.length) {
  204. out = 0;
  205. }
  206. //如果下一个写入字符的下标与下一个被读取的下标相同、则清空buf
  207. if (in == out) {
  208. /* now empty */
  209. in = -1;
  210. }
  211. }
  212. return rlen;
  213. }
  214.  
  215. /**
  216. * 查看此流是否可读、看各个线程是否关闭、以及buffer中是否有可供读取的字符。
  217. */
  218. public synchronized boolean ready() throws IOException {
  219. if (!connected) {
  220. throw new IOException("Pipe not connected");
  221. } else if (closedByReader) {
  222. throw new IOException("Pipe closed");
  223. } else if (writeSide != null && !writeSide.isAlive()
  224. && !closedByWriter && (in < 0)) {
  225. throw new IOException("Write end dead");
  226. }
  227. if (in < 0) {
  228. return false;
  229. } else {
  230. return true;
  231. }
  232. }
  233.  
  234. /**
  235. * 清空buf中数据、关闭此流。
  236. */
  237. public void close() throws IOException {
  238. in = -1;
  239. closedByReader = true;
  240. }
  241. }

4、实例演示:


            用于发送字符的线程:CharSenderThread

  1. package com.chy.io.original.thread;
  2.  
  3. import java.io.IOException;
  4. import java.io.PipedWriter;
  5.  
  6. @SuppressWarnings("all")
  7. public class CharSenderThread implements Runnable {
  8. private PipedWriter pw = new PipedWriter();
  9.  
  10. public PipedWriter getPipedWriter(){
  11. return pw;
  12. }
  13. @Override
  14. public void run() {
  15. //sendOneChar();
  16. //sendShortMessage();
  17. sendLongMessage();
  18. }
  19.  
  20. private void sendOneChar(){
  21. try {
  22. pw.write("a".charAt(0));
  23. pw.flush();
  24. pw.close();
  25. } catch (IOException e) {
  26. e.printStackTrace();
  27. }
  28. }
  29.  
  30. private void sendShortMessage() {
  31. try {
  32. pw.write("this is a short message from CharSenderThread !".toCharArray());
  33. pw.flush();
  34. pw.close();
  35. } catch (IOException e) {
  36. e.printStackTrace();
  37. }
  38. }
  39.  
  40. private void sendLongMessage(){
  41. try {
  42. char[] b = new char[1028];
  43. //生成一个长度为1028的字符数组、前1020个是1、后8个是2。
  44. for(int i=0; i<1020; i++){
  45. b[i] = 'a';
  46. }
  47. for (int i = 1020; i <1028; i++) {
  48. b[i] = 'b';
  49. }
  50. pw.write(b);
  51. pw.flush();
  52. pw.close();
  53. } catch (IOException e) {
  54. e.printStackTrace();
  55. }
  56. }
  57. }

用于接收字符的线程: CharReceiveThread


  1. package com.chy.io.original.thread;
  2.  
  3. import java.io.IOException;
  4. import java.io.PipedReader;
  5.  
  6. @SuppressWarnings("all")
  7. public class CharReceiverThread extends Thread {
  8.  
  9. private PipedReader pr = new PipedReader();
  10.  
  11. public PipedReader getPipedReader(){
  12. return pr;
  13. }
  14. @Override
  15. public void run() {
  16. //receiveOneChar();
  17. //receiveShortMessage();
  18. receiverLongMessage();
  19. }
  20.  
  21. private void receiveOneChar(){
  22. try {
  23. int n = pr.read();
  24. System.out.println(n);
  25. pr.close();
  26. } catch (IOException e) {
  27. e.printStackTrace();
  28. }
  29. }
  30.  
  31. private void receiveShortMessage() {
  32. try {
  33. char[] b = new char[1024];
  34. int n = pr.read(b);
  35. System.out.println(new String(b, 0, n));
  36. pr.close();
  37.  
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42.  
  43. private void receiverLongMessage(){
  44. try {
  45. char[] b = new char[2048];
  46. int count = 0;
  47. while(true){
  48. count = pr.read(b);
  49. for (int i = 0; i < count; i++) {
  50. System.out.print(b[i]);
  51. }
  52. if(count == -1)
  53. break;
  54. }
  55. pr.close();
  56.  
  57. } catch (IOException e) {
  58. e.printStackTrace();
  59. }
  60. }
  61.  
  62. }

        启动类:PipedWriterAndPipedReaderTest

  1. package com.chy.io.original.test;
  2.  
  3. import java.io.IOException;
  4. import java.io.PipedReader;
  5. import java.io.PipedWriter;
  6.  
  7. import com.chy.io.original.thread.CharReceiverThread;
  8. import com.chy.io.original.thread.CharSenderThread;
  9.  
  10. public class PipedWriterAndPipedReaderTest {
  11. public static void main(String[] args) throws IOException{
  12. CharSenderThread cst = new CharSenderThread();
  13. CharReceiverThread crt = new CharReceiverThread();
  14. PipedWriter pw = cst.getPipedWriter();
  15. PipedReader pr = crt.getPipedReader();
  16.  
  17. pw.connect(pr);
  18.  
  19. /**
  20. * 想想为什么下面这样写会报Piped not connect异常 ?
  21. */
  22. //new Thread(new CharSenderThread()).start();
  23. //new CharReceiverThread().start();
  24.  
  25. new Thread(cst).start();
  26. crt.start();
  27. }
  28. }

            两个线程中分别有三个方法、可以对应的每次放开一对方法来测试、还有这里最后一个读取1028个字符的方法用了死循环来读取、可以试试当不用死循环来读取会有什么不一样的效果?初始化字符的时候要用char = 'a' 而不是cahr = "a"、可自己想原因。。。

总结:


PipedReader、PipedWriter两者的结合如鸳鸯一般、离开哪一方都不能继续存在、同时又如连理枝一般、PipedWriter先通过connect(PipedReader sink)来确定关系、并初始化PipedReader状态、告诉PipedReader只能属于这个PipedWriter、connect =true、当想赠与PipedReader字符时、就直接调用receive(char c) 、receive(char[] b, int off, int len)来将字符或者字符数组放入pr的存折buffer中。站在PipedReader角度上、看上哪个PipedWriter时就暗示pw、将主动权交给pw、调用pw的connect将自己给他去登记。当想要花(将字符读取到程序中)字符了就从buffer中拿、但是自己又没有本事挣字符、所以当buffer中没有字符时、自己就等着、并且跟pw讲没有字符了、pw就会向存折(buffer)中存字符、当然、pw不会一直不断往里存、当存折是空的时候也不会主动存、怕花冒、就等着pr要、要才存。过到最后两个只通过buffer来知道对方的存在与否、每次从buffer中存或者取字符时都会看看对方是否安康、若安好则继续生活、若一方不在、则另一方也不愿独存!

更多IO内容:java_io 体系之目录

Java_io体系之PipedWriter、PipedReader简介、走进源码及示例——14的更多相关文章

  1. Java_io体系之BufferedWriter、BufferedReader简介、走进源码及示例——16

    Java_io体系之BufferedWriter.BufferedReader简介.走进源码及示例——16 一:BufferedWriter 1.类功能简介: BufferedWriter.缓存字符输 ...

  2. Java_io体系之RandomAccessFile简介、走进源码及示例——20

    Java_io体系之RandomAccessFile简介.走进源码及示例——20 RandomAccessFile 1.       类功能简介: 文件随机访问流.关心几个特点: 1.他实现的接口不再 ...

  3. java io系列13之 BufferedOutputStream(缓冲输出流)的认知、源码和示例

    本章内容包括3个部分:BufferedOutputStream介绍,BufferedOutputStream源码,以及BufferedOutputStream使用示例. 转载请注明出处:http:// ...

  4. Linux内核分析(一)---linux体系简介|内核源码简介|内核配置编译安装

    原文:Linux内核分析(一)---linux体系简介|内核源码简介|内核配置编译安装 Linux内核分析(一) 从本篇博文开始我将对linux内核进行学习和分析,整个过程必将十分艰辛,但我会坚持到底 ...

  5. Scala 深入浅出实战经典 第41讲:List继承体系实现内幕和方法操作源码揭秘

    Scala 深入浅出实战经典 第41讲:List继承体系实现内幕和方法操作源码揭秘 package com.parllay.scala.dataset /** * Created by richard ...

  6. ThreadLocal 简介 案例 源码分析 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  7. Java生鲜电商平台-电商会员体系系统的架构设计与源码解析

    Java生鲜电商平台-电商会员体系系统的架构设计与源码解析 说明:Java生鲜电商平台中会员体系作为电商平台的基础设施,重要性不容忽视.我去年整理过生鲜电商中的会员系统,但是比较粗,现在做一个最好的整 ...

  8. java io系列12之 BufferedInputStream(缓冲输入流)的认知、源码和示例

    本章内容包括3个部分:BufferedInputStream介绍,BufferedInputStream源码,以及BufferedInputStream使用示例. 转载请注明出处:http://www ...

  9. java io系列15之 DataOutputStream(数据输出流)的认知、源码和示例

    本章介绍DataOutputStream.我们先对DataOutputStream有个大致认识,然后再深入学习它的源码,最后通过示例加深对它的了解. 转载请注明出处:http://www.cnblog ...

随机推荐

  1. Oracle 学习笔记(一)Oracle的基本介绍与语法

    1.1 Oracle基础知识 1.1.1 介绍 Oracle数据库的主要特点: 支持多用户.大事务量的事务处理 在保持数据安全性和完整性方面性能优越 支持分布式数据处理 具有可移植性 1.1.2 Or ...

  2. grunt -- javascript自动化工具

    grunt 是一个基于npm,node.js 用js编写的工具框架,可以自动完成一些重复性的任务(如合并文件,语法检查,压缩代码), grunt拥有庞大的插件库,可以满足各种自动化批处理需求,常用的插 ...

  3. 自己动手写easyui的checkbox

    最近项目中用到了easyui这个框架,找了一圈也没有找到checkbox list控件,被迫只能自己实现了,为了便于复用,自己封装了下,有需要的,直接拿去用吧.有意见或建议的,欢迎指教啊. 调用示例 ...

  4. form表单提交

    1.form表单提交.html页面失败 <%--客户端form--%> <form id="form2" action="LoginOne.html&q ...

  5. maven自动下载jar包

    只需要修改pom文件即可.需要哪个jar包,在pom中就配置哪个(还包括手动向仓库中添加) 例如 http://blog.csdn.net/beyondlpf/article/details/8592 ...

  6. java第一天的疑问

    1字节 的 byte 2字节 的 char 精度 byte<short<char<int<long<float<double 随便打个整数默认为int 随便打个小数 ...

  7. 逆天的IE7中,绝对定位元素之间的遮盖问题

    个人比较支持IE9以上的版本,认为他们的样式和效果都是比较人性化的,不过很多时候还是不得不考虑其他版本浏览器的感受,这里IE6就不用考虑他了,这货简直就是IT史上的奇葩,这里要说一个IE7的绝对定位和 ...

  8. Mysql中的DQL查询语句

    ----------------1.查询所有列 --查询 学生 表所有记录(行) select *from 学生 --带条件的查询 select *from 学生 where 年龄>19 --- ...

  9. js实现数组内元素随机排序

    其实蛮容易实现的,关键是简洁与否,下面是我自己写的. function randomSort(a){ var arr = a, random = [], len = arr.length; for ( ...

  10. sudo gedit xx warning

    When I sue command "sudo gedit xx", it appeas several warning: gedit:): IBUS-WARNING **: T ...