Chinaunix首页 | 论坛 | 博客
  • 博客访问: 149791
  • 博文数量: 7
  • 博客积分: 2230
  • 博客等级: 大尉
  • 技术积分: 585
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-01 10:46
文章分类

全部博文(7)

文章存档

2011年(7)

我的朋友

分类: Java

2011-05-21 11:08:17

今天开始看Java Network Programming,3rd一书,特记笔记。
1,网络编程无处不在,
2,Java was the first programming language designed from the ground up with networking in mind
3,Java有严格的安全机制

1)Remotely loaded code cannot access arbitrary addresses in memory. Unlike the other restrictions in the list, which are enforced by a SecurityManager, this restriction is a property of the Java language itself and the byte code verifier.

2)Remotely loaded code cannot access the local filesystem. It cannot read from or write to the local filesystem nor can it find out any information about files. Therefore, it cannot find out whether a file exists or what its modification date may be. (Java WebStart applications can actually ask the user for permissions to read or write files on a case-by-case basis.)

3)Remotely loaded code cannot print documents. (Java WebStart applications can do this with the user's explicit permission on a case-by-case basis.)

4)Remotely loaded code cannot read from or write to the system clipboard. (Java WebStart applications can do this with the user's explicit permission on a case-by-case basis.) It can read from and write to its own clipboard.

5)Remotely loaded code cannot launch other programs on the client. In other words, it cannot call System.exec( ) or Runtime.exec( ).

6)Remotely loaded code cannot load native libraries or define native method calls.

7)Remotely loaded code is not allowed to use System.getProperty( ) in a way that reveals information about the user or the user's machine, such as a username or home directory. It may use System.getProperty( ) to find out what version of Java is in use.

8)Remotely loaded code may not define any system properties.

9)Remotely loaded code may not create or manipulate any Thread that is not in the same ThreadGroup.

10)Remotely loaded code cannot define or use a new instance of ClassLoader, SecurityManager, ContentHandlerFactory, SocketImplFactory, or URLStreamHandlerFactory. It must use the ones already in place.

Finally, and most importantly for this book:

11)Remotely loaded code can only open network connections to the host from which the code itself was downloaded.

12)Remotely loaded code cannot listen on ports below 1,024.

13)Even if a remotely loaded program can listen on a port, it can only accept incoming connections from the host from which the code itself was downloaded.



5)中System.exec,Runtime.exec()在OPEN-JDK1.6中没有改方法,实际的例子代码应该为:
  1. package cn.doyo.net;

  2. import java.io.BufferedReader;
  3. import java.io.DataInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;

  6. public class RunCmd {

  7.     /**
  8.      * @param args
  9.      * @throws IOException
  10.      */
  11.     public static void main(String[] args) throws IOException {
  12.         // TODO Auto-generated method stub
  13.         String cmd = "/bin/ls -l";
  14.         try {
  15.             
  16.             //方法一,readLine()方法是depratected,无法正确处理Character(does not properly convert bytes to characters)
  17.             Process p = Runtime.getRuntime().exec(cmd);
  18.             DataInputStream dis = new DataInputStream(p.getInputStream());
  19.             String line = "";
  20.             while ((line = dis.readLine()) != null) {
  21.                 System.out.println(line);
  22.             }
  23.             dis.close();
  24.             
  25.             
  26.             //方法二
  27.             p = Runtime.getRuntime().exec(cmd);
  28.             BufferedReader d = new BufferedReader(new InputStreamReader(p.getInputStream()));
  29.             while (( line = d.readLine()) != null ) {
  30.                 System.out.println(line);
  31.             }
  32.             d.close();

  33.         } catch (Exception e) {
  34.             e.printStackTrace();
  35.         }
  36.     }

  37. }




阅读(405) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~