<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11">
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml">
<!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
</style>
<![endif]-->
本文为原创,如需转载,请注明作者和出处,谢谢!
上一篇:Java网络编程从入门到精通(33):非阻塞I/O的缓冲区(Buffer)
对于缓冲区来说,最重要的操作就是读写操作。缓冲区提供了两种方法来读写缓冲区中的数据:get、put方法和array方法。而get、put方法可以有三种读写数据的方式:按顺序读写单个数据、在指定位置读写单个数据和读写数据块。除了上述的几种读写数据的方法外,CharBuffer类还提供了用于专门写字符串的put和append方法。在本文及后面的文章中将分别介绍这些读写缓冲区的方法。
虽然使用allocate方法创建的缓冲区并不是一次性地分配内存空间,但我们可以从用户地角度将一个缓冲区想象成一个长度为capacity的数组。当缓冲区创建后,和数组一样,缓冲区的大小(capacity值)将无法改变,也无法访问缓冲区外的数据。如下面的代码创建了一个大小为6的字节缓冲区。
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->ByteBufferbyteBuffer=ByteBuffer.allocate(6);
对于byteBuffer来说,只能访问属于这个缓冲区的六个字节的数据,如果超过了这个范围,将抛出一个BufferOverflowException异常,这是一个运行时错误,因为这个错误只能在程序运行时被发现。
既然缓冲区和数组类似,那么缓冲区也应该象数组一样可以标识当前的位置。缓冲区的position方法为我们提供了这个功能。position方法有两种重载形式,它们的定义如下:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->publicfinalintposition()
publicfinalBufferposition(intnewPosition)
第一个重载形式用来获取缓冲区的当前位置。在创建缓冲区后,position的初始值是0,也就是缓冲区第一个元素的位置。当从缓冲区读取一个元素后,position的值加1。我们从这一点可以看出,position方法返回的位置就是当前可以读取的元素的位置。position的取值范围从0到capacity
– 1。如果position的值等于capacity,说明缓冲区当前已经没有数据可读了。
position方法的第二个重载形式可以设置缓冲区的当前位置。参数newPosition的取值范围是0 <= newPosition < capacity。如果newPosition的值超出这个范围,position方法就会抛出一个IllegalArgumentException异常。
在大多数情况下不需要直接控制缓冲区的位置。缓冲区类提供的用于读写数据的方法可以自动地设置缓冲区的当前位置。在缓冲区类中,get和put方法用于读写缓冲区中的数据。get和put方法的定义如下:
ByteBuffer类的get和put方法:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->publicabstractbyteget()
publicabstractByteBufferput(byteb)
IntBuffer类的get和put方法:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->publicabstractintget()
publicabstractIntBufferput(inti)
其他五个缓冲区类中的get和put方法定义和上面的定义类似,只是get方法返回相应的数据类型,而put方法的参数是相应的数据类型,并且返回值的类型是相应的缓冲区类。
每当put方法向缓冲区写入一个数据后,缓冲区的当前位置都会加1。如果缓冲区的当前位置已经等于capacity,调用put方法就会抛出一个java.nio.BufferOverflowException异常。在缓冲区未初赋值的区域将被0填充。使用get方法可以得到缓冲区当前位置的数据,并使缓冲区的当前位置加1。和put方法一样,在缓冲区当前位置等于capacity时使用get方法也会抛出java.nio.BufferOverflowException异常。缓冲区的初始状态如图1所示。
图1
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11">
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml">
<!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
</style>
<![endif]--> 缓冲区的初始状态
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
</style>
<![endif]-->
从图1可以看出,在缓冲区创建之初,当前的位置和缓冲区中的数据都为0。当使用如下语句向缓冲区中写入数据后,缓冲区当前状态如图2所示。
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->byteBuffer.put((byte)2);
byteBuffer.put((byte)-1);
图2 缓冲区的当前状态
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11">
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml">
<!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
</style>
<![endif]-->
当缓冲区的当前位置如图3所示时,使用put和get方法将会抛出上述的BufferOverflowException异常。
图3 当前位置处于缓冲区尾
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11">
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml">
<!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
</style>
<![endif]-->
如果要使用get方法得到缓冲区中的指定数据,必须将缓冲区的当前位置移动到指定的位置,我们可以使用position方法将当前位置移到缓冲区的任何位置。如下面的代码将图3所示的缓冲区的当前位置设为2,并用get方法获得位置2的数据:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->byteBuffer.position(2);
System.out.println(byteBuffer.get());
上面的代码将输出3。缓冲区的当前位置为除了使用position方法,也可以使用rewind方法将缓冲区的当前位置设为0,rewind方法的定义如下:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->publicfinalBufferrewind()
在图2所示的缓冲区状态下调用rewind方法,就会得到如图4的缓冲区状态。
图4 调用rewind方法后的缓冲区状态
接下来让我们执行如下语句:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->System.out.println(byteBuffer.get());
缓冲区的状态将如图5所示。
图5 调用get方法后的缓冲区状态
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11">
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml">
<!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
</style>
<![endif]-->
缓冲区除了position和capacity外,还提供了一个标识来限制缓冲区可访问的范围。这个标识就是limit。limit和position一样,在缓冲区类中也提供了两个重载方法。用于获得和设置limit的值。limit方法的定义如下:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->publicfinalintlimit()
publicfinalBufferlimit(intnewLimit)
在初始状态下,缓冲区的limit和capacity值相同。但limit和capacity的区别是limit可以通过limit方法进行设置,而capacity在创建缓冲区时就已经指定了,并且不能改变。(在上面所讲的position方法的newPosition参数的取值范围时曾说是0 <= newPosition < capacity,其实严格地说,应是0 <= newPosition < limit)limit的其他性质和capacity一样。如在图5所示的缓冲区状态中将limit的值设为2,就变成了图6所示的状态。
图6 将limit设为2的缓冲区状态
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="ProgId" content="Word.Document">
<meta name="Generator" content="Microsoft Word 11">
<meta name="Originator" content="Microsoft Word 11">
<link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml">
<!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><!--[if !mso]>
<style>
st1":*{behavior:url(#ieooui) }
</style>
<![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style>
<!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
</style>
<![endif]-->
在这时position的值等于limit,就不能访问缓冲区的当前数据,也就是说不能使用get和put方法。否则将抛出BufferOverflowException异常。由于使用allocate创建的缓冲区并不是一次性地分配内存空间,因此,可以将缓冲区的capacity设为很大的值,如10M。缓冲区过大可能在某些环境中会使系统性能降低(如在PDA或智能插秧机中),因此,可以使用limit方法根据具体的情况来限定缓冲区的大小。当然,limit还可以表示缓冲区中实际的数据量,这将在后面讲解。下面的代码演示了如何使用limit方法来枚举缓冲区中的数据:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->while(byteBuffer.position()<byteBuffer.limit())
System.out.println(byteBuffer.get());
我们还可以用flip和hasRemaining方法来重写上面的代码。flip方法将limit设为缓冲区的当前位置。当limit等于position时,hasRemaining方法返回false,而则返回true。 flip和hasRemaining方法的定义如下:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->publicfinalBufferflip()
publicfinalbooleanhasRemaining()
下面的代码演示了如何使用hasRemaining方法来枚举缓冲区中的数据:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->while(byteBuffer.hasRemaining())
System.out.println(byteBuffer.get());
如果从缓冲区的第一个位置依次使用put方法向缓冲区写数据,当写完数据后,再使用flip方法。这样limit的值就等于缓冲区中实际的数据量了。在网络中传递数据时,可以使用这种方法来设置数据的结束位置。
为了回顾上面所讲内容,下面的代码总结了创建缓冲区、读写缓冲区中的数据、设置缓冲区的limit和position的方法。
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->package net;
importjava.nio.*;
publicclassGetPutData
{
publicstaticvoidmain(String[]args)
{
//创建缓冲区的四种方式
IntBufferintBuffer=IntBuffer.allocate(10);
ByteBufferbyteBuffer=ByteBuffer.allocateDirect(10);
CharBuffercharBuffer=CharBuffer.wrap("abcdefg");
DoubleBufferdoubleBuffer=DoubleBuffer.wrap(newdouble[]{1.1,2.2});
//向缓冲区中写入数据
intBuffer.put(1000);
intBuffer.put(2000);
System.out.println("intBuffer的当前位置:"+intBuffer.position());
intBuffer.position(1);//将缓冲区的当前位置设为1
System.out.println(intBuffer.get());//输出缓冲区的当前数据
intBuffer.rewind();//将缓冲区的当前位置设为0
System.out.println(intBuffer.get());//输出缓冲区的当前数据
byteBuffer.put((byte)20);
byteBuffer.put((byte)33);
byteBuffer.flip();//将limit设为position,在这里是2
byteBuffer.rewind();
while(byteBuffer.hasRemaining())//枚举byteBuffer中的数据
System.out.print(byteBuffer.get()+"");
while(charBuffer.hasRemaining())//枚举charBuffer中的数据
System.out.print(charBuffer.get()+"");
//枚举doubleBuffer中的数据
while(doubleBuffer.position()<doubleBuffer.limit())
System.out.print(doubleBuffer.get()+"");
}
}
运行结果:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->intBuffer的当前位置:2
2000
1000
2033abcdefg1.12.2
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="ProgId" content="Word.Document"><meta name="Generator" content="Microsoft Word 11"><meta name="Originator" content="Microsoft Word 11"><link rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtml1%5C01%5Cclip_filelist.xml"><!--[if gte mso 9]><xml>
Normal
0
7.8 磅
0
2
false
false
false
MicrosoftInternetExplorer4
</xml><![endif]--><!--[if gte mso 9]><![endif]--><style>
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:""@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
font-size:10.5pt;
font-family:"Times New Roman";}
/* Page Definitions */
@page
{}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{
mso-style-parent:"";
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
</style>
<![endif]-->
注意:如果必须使用缓冲区的大小来读取缓冲区的数据,尽量不要使用capacity,而要使用limit。如尽量不要写成如下的代码:
<!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
-->while(byteBuffer.position()<byteBuffer.capacity())
System.out.println(byteBuffer.get());
这是因为当limit比capacity小时,上面的代码将会抛出一个BufferUnderflowException异常。
国内最棒的Google Android技术社区(eoeandroid),欢迎访问!《银河系列原创教程》发布《Java Web开发速学宝典》出版,欢迎定购
分享到:
相关推荐
在工业嘈杂的生产环境中,可能发生各种意外。 一般的数据包格式是:起始头2位+...接收包格式:起始头+标志位+数据位+结束尾,先收到缓冲区里暂存,然后从缓冲区里检查起始位、结束尾。无效串口数据丢弃,有效数据处理。
Linux运维-操作系统 教程 从入门到精通101课-05-05顺序读写与随机读写.mp4
3>编程读写一个文件test.txt,每隔一秒钟向文件中写入一行数据:写时间 2007-7-30 15:16:42 20
Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(一) http://download.csdn.net/source/3268267 Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(二) ...
|------ 5.5 在对话框中进行数据交换和数据检查 |------ 5.6 使用属性对话框 |------ 5.7 使用通用对话框 |------ 5.8 建立以对话框为基础的应用 |------ 5.9 使用对话框作为子窗口 +-- 第六章 网络通信开发 |------...
STM32F10x工程_使用SPI方式读写TF卡SD卡 此程序模板为stm32F103c8t6所用;2.编译环境Keil5.14,库函数版本3.5;3.实现功能:在TF卡/SD卡根目录下创建文件MEng.txt,并把数组bmpheader写入该文件;4.硬件说明:SPI2...
这个例子是java采集java S7-S200、java S7-300、java S7-400协义数据, 可以实现数据同步图表显示,并且可以写入数据, 以上全开源,一看就知道,请放心下载,已经使用在生产上 请浏览详情 ...
java 按顺序读取文件 java 按顺序读取文件 java 按顺序读取文件
《MATLAB7.x应用系列丛书:MATLAB从入门到精通(第2版)》以MATLAB7.x软件为基础,系统讲解了MATLAB基本环境和操作方法;分章阐述了矩阵计算、数值计算、符号计算、数据可视化、数据分析、M文件编写、Simulink仿真、...
dbf-jdbc-wisecoders,JAVA 读写DBF文件工具包
无痕驱动读写-破虚拟读写无痕驱动读写-破虚拟读写无痕驱动读写-破虚拟读写无痕驱动读写-破虚拟读写无痕驱动读写-破虚拟读写无痕驱动读写-破虚拟读写无痕驱动读写-破虚拟读写无痕驱动读写-破虚拟读写无痕驱动读写-破...
Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(一) http://download.csdn.net/source/3268267 Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(二) ...
对大数据文本文件读取(按行读取)的优化,目前常规的方案有三种,第一...代码提供在RandomAccessFile基础上,整合内部缓冲区,效率会有提高,测试过程中1000w行数据用时1秒,1亿行数据用时103(比1438秒快了13倍左右)
I2C使用DMA与AT24C02通信,Tx中,利用DMA传输数据,但是起始位,设备地址,读写地址采用的是阻塞式发送,数据则是采用DMA传输;注意点:采用DMA发送应该等到BTF(发送寄存器空,移位寄存器也为空)事件后设置停止位,...
本书是专门为oracle应用开发人员提供的sql和pl/sql编程指南。通过学习本书,读者不仅可以掌握oracle常用工具oracle universal installer、net comfiguration assistant、sql developer、sql*plus的作用及使用方法...
# Java基础知识课件教程浓缩版 Java是一种跨平台、面向对象的编程语言,广泛应用于企业级应用、移动应用、游戏开发等领域。本教程为初学者设计,旨在快速掌握Java编程的核心概念。 一、Java入门 - Java概述:介绍...
Redis从入门到精通高清,迅雷播放器组件可顺利播放
基于java的开发源码-FAT文件系统读写类库 fat32-lib.zip 基于java的开发源码-FAT文件系统读写类库 fat32-lib.zip 基于java的开发源码-FAT文件系统读写类库 fat32-lib.zip 基于java的开发源码-FAT文件系统读写类库 ...
Python编程实验五:文件的读写操作-素材
有时候需要在Linux kernel--大多是在需要调试的驱动程序--中读写文件数据。在kernel中操作文件没有标准库可用,需要利用kernel的一些函数,这些函数主要有:filp_open() filp_close(), vfs_read() vfs_write(),set_...