ï»??xml version="1.0" encoding="utf-8" standalone="yes"?>99久热这里只有精品视频免费观看,国产原创一区二区三区,日韩电影免费http://www.aygfsteel.com/lazing/category/12906.htmlFuture network: Share and Create...zh-cnFri, 18 May 2007 02:24:17 GMTFri, 18 May 2007 02:24:17 GMT60Java Notes: Data types and Operatorshttp://www.aygfsteel.com/lazing/archive/2007/05/17/118189.htmlHIMMELHIMMELThu, 17 May 2007 14:48:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/05/17/118189.htmlhttp://www.aygfsteel.com/lazing/comments/118189.htmlhttp://www.aygfsteel.com/lazing/archive/2007/05/17/118189.html#Feedback0http://www.aygfsteel.com/lazing/comments/commentRss/118189.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/118189.htmlComprehend
  • A variable holds a value, while an object reference variable points to the memory that holds the object.
  • The short-circuit logical operators && and || operate only on boolean operands. For example, the expression
    9&&7 will not compile. Understand the difference between short-circuit logical operators and bitwise
    operators.
  • If the first expression of a && operator is false, the second expression is not evaluated, and if the first
    expression of a || operator is true, the second expression is not evaluated.

Look Out

  • Be on guard for words that are only slightly different from the Java keywords, such as synchronize instead of synchronized, implement instead of implements, and protect instead of protected.
  • Whether an array stores primitive variables or object references, the array itself is always an object.
  • It is illegal to include the array size in the array declaration.
  • Division by zero generates a runtime ArithmeticException only if the operands are integers. In case of float and double, the result of division by zero is infinity.
  • The result of the modulo operator always carries the sign of the first operand (i.e. the one before the operator);
    you can ignore the sign of the second operand.
  • You cannot instantiate an enum by using the new operator.

Memorize

  • Know the Java language keywords.
  • Know the range of values for all primitive data types.
  • All primitive data types except boolean and char are signed.
  • The first character of an identifier must be a letter, a dollar sign ($), or an underscore (_). Characters other than the first character in an identifier may be a letter, a dollar sign, an underscore, or a digit.


HIMMEL 2007-05-17 22:48 发表评论
]]>
Java Notes: Classes, Methods, and Interfacehttp://www.aygfsteel.com/lazing/archive/2007/05/17/118188.htmlHIMMELHIMMELThu, 17 May 2007 14:47:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/05/17/118188.htmlhttp://www.aygfsteel.com/lazing/comments/118188.htmlhttp://www.aygfsteel.com/lazing/archive/2007/05/17/118188.html#Feedback0http://www.aygfsteel.com/lazing/comments/commentRss/118188.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/118188.htmlComprehend
  • The method name and return type are mandatory in a method declaration. Even though you are not required to specify a modifier in a method declaration, the default modifier is assigned to the method, if you don’t declare one.
  • A static variable belongs to the class and not to a particular instance of the class, and therefore is initialized when the class is loaded, and before the class is instantiated.
  • Because a static method belongs to a class and not to a particular instance of the class, it cannot access the nonstatic methods and variables of the class in which it is defined.
  • An instance of an inner class can only exist in an instance of the outer class, and has direct access to all the instance variables and methods of the outer instance.
  • If you make a super call or a this call, it must be in the beginning of a constructor. That means you can make either a super call or a this call, but not both.

Look Out

  • The variable-length parameters list must appear last in the parentheses of a method and it consists of a data type, three dots, and a name, in that order.
  • A Java class cannot inherit from more than one class, but it can inherit from one class and one or more interfaces.
  • The class that inherits from an interface must provide implementation for all the methods that are declared in the interface if the class is not abstract.
  • An interface can extend another interface but it cannot implement another interface or a class.

Memorize

  • If you do not provide any constructor for a class you write, the compiler provides the default constructor for that class. If you write at least one constructor for the class, the compiler provides no constructor.
  • If you don not make a this or a super call in the beginning of a constructor, the compiler places a super() call there.
  • You use the keyword extends to write a derived class that inherits from a parent class, and use the keyword implements to write a class that inherits from an interface.
  • The methods in an interface are inherently public and abstract, and the variables in the interface are inherently public, final, and static.


HIMMEL 2007-05-17 22:47 发表评论
]]>
JavaMail API 实例汇æ€?/title><link>http://www.aygfsteel.com/lazing/archive/2007/05/17/118184.html</link><dc:creator>HIMMEL</dc:creator><author>HIMMEL</author><pubDate>Thu, 17 May 2007 14:30:00 GMT</pubDate><guid>http://www.aygfsteel.com/lazing/archive/2007/05/17/118184.html</guid><wfw:comment>http://www.aygfsteel.com/lazing/comments/118184.html</wfw:comment><comments>http://www.aygfsteel.com/lazing/archive/2007/05/17/118184.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/lazing/comments/commentRss/118184.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/lazing/services/trackbacks/118184.html</trackback:ping><description><![CDATA[<div id="wmqeeuq" class="postentry"> <p>呃,好吧åQŒæˆ‘只写˜q‡ä¸‰ä¸ªJavaMail的程序ã€?/p> <p>都是扚w‡é‚®äšg守护½E‹åºã€‚决定æ€È»“一下,希望非常òq¸è¿æ‰‘Öˆ°˜q™ç¯‡æ–‡ç« çš„äh不会再对˜q™ä¸ªå›°æƒ‘ã€?/p> <h3>必须明白的基¼‹€çŸ¥è¯†</h3> <ol> <li>STMP协议是如何工作的<br> 协议的标准在˜q™é‡Œ <a >http://www.ietf.org/rfc/rfc2821.txt?number=2821</a><br> 下面是扼要说明(<a >http://www.freesoft.org/CIE/Topics/94.htm</a> åQ‰ï¼š <blockquote> <p>Simple Mail Transfer Protocol (SMTP), documented in RFC 821, is Internet’s standard host-to-host mail transport protocol and traditionally operates over TCP, port 25. In other words, a UNIX user can type telnet hostname 25 and connect with an SMTP server, if one is present.</p> <p>SMTP uses a style of asymmetric request-response protocol popular in the early 1980s, and still seen occasionally, most often in mail protocols. The protocol is designed to be equally useful to either a computer or a human, though not too forgiving of the human. From the server’s viewpoint, a clear set of commands is provided and well-documented in the RFC. For the human, all the commands are clearly terminated by newlines and a HELP command lists all of them. From the sender’s viewpoint, the command replies always take the form of text lines, each starting with a three-digit code identifying the result of the operation, a continuation character to indicate another lines following, and then arbitrary text information designed to be informative to a human.</p> </blockquote> <p>事实上,你可以像使用DOS命ä×o一样发送电子邮件ã€?a >http://bbs.stcore.com/archiver/tid-8024.htm </a>å½“ç„¶å› äØ“å„ç§åŽŸå› åQŒä½ çš„尝试不可能成功。事实上SMTPå·¥ä½œçš„æ—¶å€™å°±æ˜¯ç®€å•çš„å‘é€å‘½ä»¤ã€‚å–å¾—è®¤è¯ï¼Œå‘é€æ•°æ®ã€‚å¾—åˆ°åé¦ˆã€‚ç¡®è®¤é€€å‡ø™¿™ä¹ˆç®€å•ã€? </p> </li> <li>SMTP中用于发送的数据<br> SMTP中发送的数据åQŒéµä»?font size="-1"><strong>Multipurpose Internet Mail</strong> <strong>Extensions</strong> (<strong>MIME</strong>)标准åQŒå‘ƒåQŒæˆ‘不得不说åQŒè¿™æ˜¯è¿™ä¸ªæ˜Ÿçƒä¸Šæœ€é‡è¦çš„æ ‡å‡†ä¹‹ä¸€ã€‚所有的互联¾|‘通信基本都是åŸÞZºŽ˜q™ä¸ªæ ‡å‡†çš„æ¼”化。除了电子邮ä»Óž¼Œå¸¸è§çš„应用还包括HTTP报文½{‰ï¼ˆä¹Ÿå°±æ˜¯æ‰€æœ‰ç½‘™åµäº†åQ‰ï¼Œå¦å¤–即ä‹Éåœ?0òq´åŽå‘展的XMLåQŒå…¶2˜q›åˆ¶æ•°æ®å‘送仍然实用的MIME中的¾~–码方式ã€?br> 恩,˜q™é‡Œž®±æ¶‰åŠåˆ°é‚®äšg附äšg如何处理的问题。恩åQŒç®€å•地说就是BASE64¾~–码</font></li> </ol> <blockquote> <pre>Table 1: The Base64 Alphabet<br><br>Value Encoding Value Encoding Value Encoding Value Encoding</pre> <pre>0 A 17 R 34 i 51 z<br><br>1 B 18 S 35 j 52 0<br><br>2 C 19 T 36 k 53 1<br><br>3 D 20 U 37 l 54 2<br><br>4 E 21 V 38 m 55 3<br><br>5 F 22 W 39 n 56 4<br><br>6 G 23 X 40 o 57 5<br><br>7 H 24 Y 41 p 58 6<br><br>8 I 25 Z 42 q 59 7<br><br>9 J 26 a 43 r 60 8<br><br>10 K 27 b 44 s 61 9<br><br>11 L 28 c 45 t 62 +<br><br>12 M 29 d 46 u 63 /<br><br>13 N 30 e 47 v<br><br>14 O 31 f 48 w (pad) =<br><br>15 P 32 g 49 x<br><br>16 Q 33 h 50 y</pre> </blockquote> <p>在这¿Uç¼–码中åQŒæˆ‘们将字符或者二˜q›åˆ¶¾~–码ä»?个比特位ä¸ÞZ¸€¾l„,替换成相应的字符形式。比å¦?/p> <pre>100110111010001011101001</pre> <p>转换¾l“æžœž®±æ˜¯</p> <pre>100110 -> 38</pre> <pre>111010 -> 58<br><br>001011 -> 11<br><br>101001 -> 41</pre> <pre>38 -> m<br><br>58 -> 6<br><br>11 -> L<br><br>41 -> p</pre> <pre>m6Lp</pre> <p>于是åQŒæˆ‘们就可以以文本的方式¾~–码二进制流以及扩展ASCII字符åQŒæ¯”如中文字½W¦ã€?/p> <p>基础知识完毕åQŒä¸‹é¢æ˜¯FAQ</p> <h3>Java发送电子邮仉™œ€è¦å“ªäº›èÊY件包</h3> <p>mail.jar 通常˜q˜ä¼šéœ€è¦?activation.jar</p> <blockquote> <p>下蝲地址<br> http://java.sun.com/products/javabeans/jaf/downloads/index.html<br> https://maven-repository.dev.java.net/nonav/repository/javax.mail/</p> </blockquote> <h3>如何发送邮ä»?/h3> <p>关于åQ?/p> <ul> <li>如何发送邮ä»?/li> <li>如何发送带有附件的邮äšg</li> <li>如何发送中文邮ä»?/li> <li>é‚®äšg中文标题ä¹Þq æ€Žä¹ˆåŠ?/li> <li>é‚®äšg附äšgä¹Þq æ€Žä¹ˆåŠžç­‰½{‰é—®é¢?/li> </ul> <p>è¯ähŸ¥çœ‹ä»¥ä¸‹ä»£ç ?/p> <pre class="java"> <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">static</span> <span style="color: blue; font-weight: bold;">synchronized</span> <span style="color: #993333;">void</span> sendMail<span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">Properties</span></a> settings<span style="color: #66cc66;">)</span><br> <br> <span style="color: blue; font-weight: bold;">throws</span> <a ><span style="color: red; font-weight: bold;">Exception</span></a> <span style="color: #66cc66;">{</span><br> <br> <a ><span style="color: red; font-weight: bold;">Properties</span></a> props = <span style="color: blue; font-weight: bold;">new</span> <a ><span style="color: red; font-weight: bold;">Properties</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> props.<span style="color: #006600;">put</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"mail.smtp.host"</span>, settings.<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">MAIL_SERVER</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br> props.<span style="color: #006600;">put</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"mail.smtp.user"</span>, settings.<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">USER_NAME</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br> props.<span style="color: #006600;">put</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"mail.smtp.auth"</span>, <span style="color: #ff0000;">"true"</span><span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//SMTP服务器用户验è¯?/span><br> <br> <a ><span style="color: red; font-weight: bold;">Authenticator</span></a> auth = <span style="color: blue; font-weight: bold;">new</span> SMTPAuthenticator<span style="color: #66cc66;">(</span><span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a><span style="color: #66cc66;">)</span> settings<br> <br> .<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">USER_NAME</span><span style="color: #66cc66;">)</span>, <span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a><span style="color: #66cc66;">)</span> settings<br> <br> .<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">PASSWORD</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br> Session session = Session.<span style="color: #006600;">getDefaultInstance</span><span style="color: #66cc66;">(</span>props, auth<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #ff0000;">"true"</span>.<span style="color: #006600;">compareToIgnoreCase</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a><span style="color: #66cc66;">)</span> settings.<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"DEBUG"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> == <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span><br> <br> session.<span style="color: #006600;">setDebug</span><span style="color: #66cc66;">(</span><span style="color: blue; font-weight: bold;">true</span><span style="color: #66cc66;">)</span>;<br> <br> <span style="color: #66cc66;">}</span><br> <br><span style="color: #808080; font-style: italic;">//创徏消息ä½?/span><br> <br> MimeMessage msg = <span style="color: blue; font-weight: bold;">new</span> MimeMessage<span style="color: #66cc66;">(</span>session<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//讄¡½®å‘送ähé‚®äšg</span><br> <br> msg.<span style="color: #006600;">setFrom</span><span style="color: #66cc66;">(</span><span style="color: blue; font-weight: bold;">new</span> InternetAddress<span style="color: #66cc66;">(</span><span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a><span style="color: #66cc66;">)</span> settings<br> <br> .<span style="color: #006600;">get</span><span style="color: #66cc66;">(</span>StartCore.<span style="color: #006600;">USER_MAIL</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//讄¡½®æŽ¥æ”¶äººé‚®ä»?/span><br> <br> address = <span style="color: blue; font-weight: bold;">new</span> InternetAddress<span style="color: #66cc66;">[</span><span style="color: #66cc66;">]</span> <span style="color: #66cc66;">{</span> <span style="color: blue; font-weight: bold;">new</span> InternetAddress<span style="color: #66cc66;">(</span>rs<br> <br> .<span style="color: #006600;">getString</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"GRE_mail"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">}</span>;<br> <br> msg.<span style="color: #006600;">setRecipients</span><span style="color: #66cc66;">(</span>Message.<span style="color: #006600;">RecipientType</span>.<span style="color: #006600;">TO</span>, address<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//讄¡½®ä¸»é¢˜åQŒä¸­æ–‡ç¼–ç ?/span><br> <br> msg.<span style="color: #006600;">setSubject</span><span style="color: #66cc66;">(</span>subject, <span style="color: #ff0000;">"gbk"</span><span style="color: #66cc66;">)</span>;<br> <br> msg.<span style="color: #006600;">setSentDate</span><span style="color: #66cc66;">(</span><span style="color: blue; font-weight: bold;">new</span> <a ><span style="color: red; font-weight: bold;">Date</span></a><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br><a ><span style="color: red; font-weight: bold;">String</span></a> content = <span style="color: #ff0000;">"é‚®äšg正文"</span>;<br> <br> MimeBodyPart mbp1 = <span style="color: blue; font-weight: bold;">new</span> MimeBodyPart<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> mbp1.<span style="color: #006600;">setText</span><span style="color: #66cc66;">(</span>content, <span style="color: #ff0000;">"gbk"</span><span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">//é‚®äšg附äšg</span><br> <br>MimeBodyPart attachFilePart = <span style="color: blue; font-weight: bold;">new</span> MimeBodyPart<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br><a ><span style="color: red; font-weight: bold;">File</span></a> file = <span style="color: blue; font-weight: bold;">new</span> <a ><span style="color: red; font-weight: bold;">File</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"中文附äšg.txt"</span><span style="color: #66cc66;">)</span>;<br> <br>FileDataSource fds = <span style="color: blue; font-weight: bold;">new</span> FileDataSource<span style="color: #66cc66;">(</span>file.<span style="color: #006600;">getName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br>attachFilePart.<span style="color: #006600;">setDataHandler</span><span style="color: #66cc66;">(</span><span style="color: blue; font-weight: bold;">new</span> DataHandler<span style="color: #66cc66;">(</span>fds<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;<br> <br> sun.<span style="color: #006600;">misc</span>.<span style="color: #006600;">BASE64Encoder</span> enc = <span style="color: blue; font-weight: bold;">new</span> sun.<span style="color: #006600;">misc</span>.<span style="color: #006600;">BASE64Encoder</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> <span style="color: #808080; font-style: italic;">//解决中文附äšg名称</span><br> <br> attachFilePart.<span style="color: #006600;">setFileName</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"=?gbk?B?"</span><br> <br> + enc.<span style="color: #006600;">encode</span><span style="color: #66cc66;">(</span>file.<span style="color: #006600;">getName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>.<span style="color: #006600;">getBytes</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"gbk"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> + <span style="color: #ff0000;">"?="</span><span style="color: #66cc66;">)</span>;<br> <br>Multipart mp = <span style="color: blue; font-weight: bold;">new</span> MimeMultipart<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> mp.<span style="color: #006600;">addBodyPart</span><span style="color: #66cc66;">(</span>mbp1<span style="color: #66cc66;">)</span>;<br> <br> mp.<span style="color: #006600;">addBodyPart</span><span style="color: #66cc66;">(</span>attachFilePart<span style="color: #66cc66;">)</span>;<br> <br>msg.<span style="color: #006600;">setContent</span><span style="color: #66cc66;">(</span>mp<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #808080; font-style: italic;">// send the message</span><br> <br> msg.<span style="color: #006600;">saveChanges</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;<br> <br> Transport.<span style="color: #006600;">send</span><span style="color: #66cc66;">(</span>msg<span style="color: #66cc66;">)</span>;<br> <br><span style="color: #66cc66;">}</span></pre> <p>˜q™æ˜¯ä¸Šé¢ç”¨æˆ·éªŒè¯ç”¨åˆ°çš„ç±»</p> <pre class="java"><span style="color: blue; font-weight: bold;">class</span> SMTPAuthenticator <span style="color: blue; font-weight: bold;">extends</span> javax.<span style="color: #006600;">mail</span>.<a ><span style="color: red; font-weight: bold;">Authenticator</span></a> <span style="color: #66cc66;">{</span></pre> <pre class="java"> <span style="color: blue; font-weight: bold;">private</span> <a ><span style="color: red; font-weight: bold;">String</span></a> username;<br> <br> <span style="color: blue; font-weight: bold;">private</span> <a ><span style="color: red; font-weight: bold;">String</span></a> password;<br> <br> <span style="color: #808080; font-style: italic;">/**<br> <br> * @param username<br> <br> * @param password<br> <br> */</span><br> <br> <span style="color: blue; font-weight: bold;">public</span> SMTPAuthenticator<span style="color: #66cc66;">(</span><a ><span style="color: red; font-weight: bold;">String</span></a> username, <a ><span style="color: red; font-weight: bold;">String</span></a> password<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span><br> <br> <span style="color: blue; font-weight: bold;">this</span>.<span style="color: #006600;">username</span> = username;<br> <br> <span style="color: blue; font-weight: bold;">this</span>.<span style="color: #006600;">password</span> = password;<br> <br> <span style="color: #66cc66;">}</span><br> <br> <span style="color: blue; font-weight: bold;">public</span> <a ><span style="color: red; font-weight: bold;">PasswordAuthentication</span></a> getPasswordAuthentication<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span><br> <br> <span style="color: blue; font-weight: bold;">return</span> <span style="color: blue; font-weight: bold;">new</span> <a ><span style="color: red; font-weight: bold;">PasswordAuthentication</span></a><span style="color: #66cc66;">(</span>username, password<span style="color: #66cc66;">)</span>;<br> <br> <span style="color: #66cc66;">}</span><br> <br><span style="color: #66cc66;">}</span></pre> <h3>é‚®äšg发送出é”?/h3> <blockquote> <p>What causes an “javax.activation.UnsupportedDataTypeException: no object DCH for MIME type xxx/xxxx javax.mail.MessagingException: IOException while sending message;” to be sent and how do I fix this? [This happens for known MIME types like text/htm</p> </blockquote> <p>事实上这个是邮äšg发送时验证¾l„äšg讄¡½®ä¸å½“引è“v的,˜q™ä¸ª¾l„äšg配置æ–ÒŽ³•如下</p> <blockquote> <p>(http://java.sun.com/j2ee/1.4/docs/api/javax/activation/MailcapCommandMap.html)</p> <p>The MailcapCommandMap looks in various places in the user’s system for mailcap file entries. When requests are made to search for commands in the MailcapCommandMap, it searches mailcap files in the following order:</p> <p>1) Programatically added entries to the MailcapCommandMap instance.<br> 2) The file .mailcap in the user’s home directory.<br> 3) The file /lib/mailcap.<br> 4) The file or resources named META-INF/mailcap.<br> 5) The file or resource named META-INF/mailcap.default (usually found only in the activation.jar file).</p> </blockquote> <p>我选用了第四种æ–ÒŽ³•åQŒåœ¨ç”Ÿæˆçš„Jaræ–‡äšg中加入了 META-INF/mailcap.</p> <pre class="apache"><span style="color: #adadad; font-style: italic;">#</span><br><span style="color: #adadad; font-style: italic;"># This is a very simple 'mailcap' file</span><br><span style="color: #adadad; font-style: italic;">#</span><br>image/gif;; x-java-view=com.sun.activation.viewers.ImageViewer<br>image/jpeg;; x-java-view=com.sun.activation.viewers.ImageViewer<br>text/*;; x-java-view=com.sun.activation.viewers.TextViewer<br>text/*;; x-java-edit=com.sun.activation.viewers.TextEditor<br>text/html;; x-java-content-handler=com.sun.mail.handlers.text_html<br>text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml<br>text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain<br>multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed<br>message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822</pre> </div><img src ="http://www.aygfsteel.com/lazing/aggbug/118184.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/lazing/" target="_blank">HIMMEL</a> 2007-05-17 22:30 <a href="http://www.aygfsteel.com/lazing/archive/2007/05/17/118184.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java IO note 1http://www.aygfsteel.com/lazing/archive/2007/01/03/91592.htmlHIMMELHIMMELWed, 03 Jan 2007 09:25:00 GMThttp://www.aygfsteel.com/lazing/archive/2007/01/03/91592.htmlhttp://www.aygfsteel.com/lazing/comments/91592.htmlhttp://www.aygfsteel.com/lazing/archive/2007/01/03/91592.html#Feedback0http://www.aygfsteel.com/lazing/comments/commentRss/91592.htmlhttp://www.aygfsteel.com/lazing/services/trackbacks/91592.html Return value of read()

For instance, according to the Java class library documentation, the read( ) method of java.io.InputStream returns "the next byte of data, or -1 if the end of the stream is reached." Upon reflection, this sounds suspicious. How is a -1 that appears as part of the stream data to be distinguished from a -1 indicating end of stream? In point of fact, the read( ) method does not return a byte; its signature shows that it returns an int:

1 public   abstract   int  read( )  throws  IOException

This int is not a Java byte with a value between -128 and 127 but a more general unsigned byte with a value between 0 and 255. Hence, -1 can easily be distinguished from valid data values read from the stream.


JVM and byte, byte array

In fact, a single byte still takes up four bytes of space inside the Java virtual machine, but a byte array occupies only the amount of space it actually needs. The virtual machine includes special instructions for operating on byte arrays but does not include any instructions for operating on single bytes. They're just promoted to ints.


Input, Output, Reader and Writer

For the most part, these classes have methods that are extremely similar to the equivalent stream classes. Often the only difference is that a byte in the signature of a stream method becomes a char in the signature of the matching reader or writer method. For example, the java.io.OutputStream class declares these three write( ) methods:

				

The java.io.Writer class, therefore, declares these three write( ) methods:

				

As you can see, the signatures match except that in the latter two methods the byte array data has changed to a char array. There's also a less obvious difference not reflected in the signature. While the int passed to the OutputStream write( ) method is reduced modulo 256 before being output, the int passed to the Writer write( ) method is reduced modulo 65,536. This reflects the different ranges of chars and bytes.

java.io.Writer also has two more write( ) methods that take their data from a string:

				public void write(String s) 
throws IOException
public void write(String s, int offset, int length) throws IOException

Because streams don't know how to deal with character-based data, there are no corresponding methods in the java.io.OutputStream class.


Hello World!

 

1   byte [] hello  =   { 72 ,  101 ,  108 ,  108 ,  111 ,  32 ,  87 ,  111 ,  114 ,  108 ,  100 ,  33 ,  10 , 13 } ;
2 System.out.write(hello);

Del.icio.us : ,

Powered by Zoundry



HIMMEL 2007-01-03 17:25 发表评论
]]>
Ö÷Õ¾Ö©Öë³ØÄ£°å£º çõ´ºÊÐ| ¿ûÇàÇø| ÒÊË®ÏØ| Ã×Ò×ÏØ| ÈÚË®| ÀÖɽÊÐ| ³Æ¶àÏØ| ´óÓàÏØ| ÍþÄþ| Ä«Öñ¹¤¿¨ÏØ| Î÷ÏçÏØ| Ì«¿µÏØ| ÇØ»ÊµºÊÐ| ʯÊ×ÊÐ| ÌìµÈÏØ| ÎÂËÞÏØ| ½­»ª| °°É½ÊÐ| Óñ»·ÏØ| ³¯ÑôÏØ| äàÑôÊÐ| Ì«ÆÍËÂÆì| çõ´ºÊÐ| Îâ½­ÊÐ| ±£¶¨ÊÐ| ÎÚËÕÊÐ| ¶«Ïç×å×ÔÖÎÏØ| µ¦³ÇÏØ| ÎåÕ¯ÏØ| ½ðÑôÏØ| ¸ï¼ªÏØ| ¼ªË®ÏØ| ÉîË®ˆ¶Çø| ÐÂÐËÏØ| »´±±ÊÐ| ÔÀÆÕºþÏØ| ºÍÆ½ÏØ| ´óÐËÇø| ̨ɽÊÐ| ·áÔ­ÊÐ| ÎäÒØÏØ|