1. /**
  2. *Java获取IP代码
  3. */
  4. import java.awt.GridLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.net.InetAddress;
  8. import java.net.UnknownHostException;
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11. import javax.swing.JLabel;
  12. import javax.swing.JPanel;
  13. import javax.swing.JTextField;
  14.  
  15. public class ip extends JFrame
  16. implements ActionListener
  17. {
  18. private static final long serialVersionUID = 3339481369781127417L;
  19. JButton jb1;
  20. JButton jb2;
  21. JButton jb3;
  22. JPanel jp;
  23. JLabel jl;
  24. JLabel jl1;
  25. JTextField jt;
  26.  
  27. public ip()
  28. {
  29. this.jp = new JPanel();
  30. this.jl = new JLabel();
  31. this.jl1 = new JLabel("您的域名:");
  32. this.jb1 = new JButton("提交");
  33. this.jb2 = new JButton("重置");
  34. this.jb3 = new JButton("退出");
  35. this.jt = new JTextField(20);
  36. this.jb1.addActionListener(this);
  37. this.jb2.addActionListener(this);
  38. this.jb3.addActionListener(this);
  39. this.jp.setLayout(new GridLayout(3, 2));
  40. this.jp.add(this.jl1);
  41. this.jp.add(this.jt);
  42. this.jp.add(this.jb1);
  43. this.jp.add(this.jl);
  44. this.jp.add(this.jb2);
  45. this.jp.add(this.jb3);
  46.  
  47. setBounds(200, 200, 500, 240);
  48. add(this.jp);
  49. setVisible(true);
  50. setDefaultCloseOperation(3);
  51. }
  52.  
  53. public static void main(String[] args)
  54. {
  55. new ip();
  56. }
  57.  
  58. public void actionPerformed(ActionEvent e) {
  59. if (e.getSource() == this.jb1) {
  60. String url = this.jt.getText();
  61. InetAddress ip = null;
  62. try {
  63. ip = InetAddress.getByName(url);
  64. }
  65. catch (UnknownHostException e1) {
  66. e1.printStackTrace();
  67. }
  68. this.jl.setText(ip.toString());
  69. }
  70. else if (e.getSource() == this.jb2) {
  71. this.jl.setText("");
  72. this.jt.setText("");
  73. } else {
  74. System.exit(0);
  75. }
  76. }
  77. }
  1. /**
  2. * 人民币转成大写
  3. *
  4. * @param value
  5. * @return String
  6. */
  7. public static String hangeToBig(double value)
  8. {
  9. char[] hunit = { '拾', '佰', '仟' }; // 段内位置表示
  10. char[] vunit = { '万', '亿' }; // 段名表示
  11. char[] digit = { '零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖' }; // 数字表示
  12. long midVal = (long) (value * 100); // 转化成整形
  13. String valStr = String.valueOf(midVal); // 转化成字符串
  14.  
  15. String head = valStr.substring(0, valStr.length() - 2); // 取整数部分
  16. String rail = valStr.substring(valStr.length() - 2); // 取小数部分
  17.  
  18. String prefix = ""; // 整数部分转化的结果
  19. String suffix = ""; // 小数部分转化的结果
  20. // 处理小数点后面的数
  21. if (rail.equals("00"))
  22. { // 如果小数部分为0
  23. suffix = "整";
  24. }
  25. else
  26. {
  27. suffix = digit[rail.charAt(0) - '0'] + "角" + digit[rail.charAt(1) - '0'] + "分"; // 否则把角分转化出来
  28. }
  29. // 处理小数点前面的数
  30. char[] chDig = head.toCharArray(); // 把整数部分转化成字符数组
  31. char zero = '0'; // 标志'0'表示出现过0
  32. byte zeroSerNum = 0; // 连续出现0的次数
  33. for (int i = 0; i < chDig.length; i++)
  34. { // 循环处理每个数字
  35. int idx = (chDig.length - i - 1) % 4; // 取段内位置
  36. int vidx = (chDig.length - i - 1) / 4; // 取段位置
  37. if (chDig[i] == '0')
  38. { // 如果当前字符是0
  39. zeroSerNum++; // 连续0次数递增
  40. if (zero == '0')
  41. { // 标志
  42. zero = digit[0];
  43. }
  44. else if (idx == 0 && vidx > 0 && zeroSerNum < 4)
  45. {
  46. prefix += vunit[vidx - 1];
  47. zero = '0';
  48. }
  49. continue;
  50. }
  51. zeroSerNum = 0; // 连续0次数清零
  52. if (zero != '0')
  53. { // 如果标志不为0,则加上,例如万,亿什么的
  54. prefix += zero;
  55. zero = '0';
  56. }
  57. prefix += digit[chDig[i] - '0']; // 转化该数字表示
  58. if (idx > 0)
  59. prefix += hunit[idx - 1];
  60. if (idx == 0 && vidx > 0)
  61. {
  62. prefix += vunit[vidx - 1]; // 段结束位置应该加上段名如万,亿
  63. }
  64. }
  65.  
  66. if (prefix.length() > 0)
  67. prefix += '圆'; // 如果整数部分存在,则有圆的字样
  68. return prefix + suffix; // 返回正确表示
  69. }
  1. //哈弗曼编码的实现类
  2. public class HffmanCoding {
  3. private int charsAndWeight[][];// [][0]是 字符,[][1]存放的是字符的权值(次数)
  4. private int hfmcoding[][];// 存放哈弗曼树
  5. private int i = 0;// 循环变量
  6. private String hcs[];
  7.  
  8. public HffmanCoding(int[][] chars) {
  9. // TODO 构造方法
  10. charsAndWeight = new int[chars.length][2];
  11. charsAndWeight = chars;
  12. hfmcoding = new int[2 * chars.length - 1][4];// 为哈弗曼树分配空间
  13. }
  14.  
  15. // 哈弗曼树的实现
  16. public void coding() {
  17. int n = charsAndWeight.length;
  18. if (n == 0)
  19. return;
  20. int m = 2 * n - 1;
  21. // 初始化哈弗曼树
  22. for (i = 0; i < n; i++) {
  23. hfmcoding[i][0] = charsAndWeight[i][1];// 初始化哈弗曼树的权值
  24. hfmcoding[i][1] = 0;// 初始化哈弗曼树的根节点
  25. hfmcoding[i][2] = 0;// 初始化哈弗曼树的左孩子
  26. hfmcoding[i][3] = 0;// 初始化哈弗曼树的右孩子
  27. }
  28. for (i = n; i < m; i++) {
  29. hfmcoding[i][0] = 0;// 初始化哈弗曼树的权值
  30. hfmcoding[i][1] = 0;// 初始化哈弗曼树的根节点
  31. hfmcoding[i][2] = 0;// 初始化哈弗曼树的左孩子
  32. hfmcoding[i][3] = 0;// 初始化哈弗曼树的右孩子
  33. }
  34.  
  35. // 构建哈弗曼树
  36. for (i = n; i < m; i++) {
  37. int s1[] = select(i);// 在哈弗曼树中查找双亲为零的 weight最小的节点
  38. hfmcoding[s1[0]][1] = i;// 为哈弗曼树最小值付双亲
  39. hfmcoding[s1[1]][1] = i;
  40. hfmcoding[i][2] = s1[0];// 新节点的左孩子
  41. hfmcoding[i][3] = s1[1];// 新节点的右孩子
  42. hfmcoding[i][0] = hfmcoding[s1[0]][0] + hfmcoding[s1[1]][0];// 新节点的权值是左右孩子的权值之和
  43. }
  44.  
  45. }
  46.  
  47. // 查找双亲为零的 weight最小的节点
  48. private int[] select(int w) {
  49. // TODO Auto-generated method stub
  50. int s[] = { -1, -1 }, j = 0;// s1 最小权值且双亲为零的节点的序号 , i 是循环变量
  51. int min1 = 32767, min2 = 32767;
  52. for (j = 0; j < w; j++) {
  53. if (hfmcoding[j][1] == 0) {// 只在尚未构造二叉树的结点中查找(双亲为零的节点)
  54. if (hfmcoding[j][0] < min1) {
  55. min2 = min1;
  56. s[1] = s[0];
  57. min1 = hfmcoding[j][0];
  58. s[0] = j;
  59.  
  60. } else if (hfmcoding[j][0] < min2) {
  61. min2 = hfmcoding[j][0];
  62. s[1] = j;
  63. }
  64. }
  65. }
  66.  
  67. return s;
  68. }
  69.  
  70. public String[] CreateHCode() {// 根据哈夫曼树求哈夫曼编码
  71. int n = charsAndWeight.length;
  72. int i, f, c;
  73. String hcodeString = "";
  74. hcs = new String[n];
  75. for (i = 0; i < n; i++) {// 根据哈夫曼树求哈夫曼编码
  76. c = i;
  77. hcodeString = "";
  78. f = hfmcoding[i][1]; // f 哈弗曼树的根节点
  79. while (f != 0) {// 循序直到树根结点
  80. if (hfmcoding[f][2] == c) {// 处理左孩子结点
  81. hcodeString += "0";
  82. } else {
  83. hcodeString += "1";
  84. }
  85. c = f;
  86. f = hfmcoding[f][1];
  87. }
  88. hcs[i] = new String(new StringBuffer(hcodeString).reverse());
  89. }
  90. return hcs;
  91. }
  92.  
  93. public String show(String s) {// 对字符串显示编码
  94. String textString = "";
  95. char c[];
  96. int k = -1;
  97. c = new char[s.length()];
  98. c = s.toCharArray();// 将字符串转化为字符数组
  99. for (int i = 0; i < c.length; i++) {
  100. k = c[i];
  101. for (int j = 0; j < charsAndWeight.length; j++)
  102. if (k == charsAndWeight[j][0])
  103. textString += hcs[j];
  104. }
  105. return textString;
  106.  
  107. }
  108.  
  109. // 哈弗曼编码反编译
  110. public String reCoding(String s) {
  111.  
  112. String text = "";// 存放反编译后的字符
  113. int k = 0, m = hfmcoding.length - 1;// 从根节点开始查询
  114. char c[];
  115. c = new char[s.length()];
  116. c = s.toCharArray();
  117. k = m;
  118. for (int i = 0; i < c.length; i++) {
  119. if (c[i] == '0') {
  120. k = hfmcoding[k][2];// k的值为根节点左孩子的序号
  121. if (hfmcoding[k][2] == 0 && hfmcoding[k][3] == 0)// 判断是不是叶子节点,条件(左右孩子都为零)
  122. {
  123. text += (char) charsAndWeight[k][0];
  124. k = m;
  125. }
  126. }
  127. if (c[i] == '1') {
  128. k = hfmcoding[k][3];// k的值为根节点右孩子的序号
  129. if (hfmcoding[k][2] == 0 && hfmcoding[k][3] == 0)// 判断是不是叶子节点,条件(左右孩子都为零)
  130. {
  131. text += (char) charsAndWeight[k][0];
  132. k = m;
  133. }
  134.  
  135. }
  136. }
  137. return text;
  138. }
  139. }
  1. //java各种数据库连接
  2. //MySQL:
  3. String Driver="com.mysql.jdbc.Driver"; //驱动程序
  4. String URL="jdbc:mysql://localhost:3306/db_name"; //连接的URL,db_name为数据库名
  5. String Username="username"; //用户名
  6. String Password="password"; //密码
  7. Class.forName(Driver).new Instance();
  8. Connection con=DriverManager.getConnection(URL,Username,Password);
  9. Microsoft SQL Server 2.0驱动(3jar的那个):
  10. String Driver="com.microsoft.jdbc.sqlserver.SQLServerDriver"; //连接SQL数据库的方法
  11. String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name为数据库名
  12. String Username="username"; //用户名
  13. String Password="password"; //密码
  14. Class.forName(Driver).new Instance(); //加载数据可驱动
  15. Connection con=DriverManager.getConnection(URL,UserName,Password); //
  16. Microsoft SQL Server 3.0驱动(1jar的那个): // 老紫竹完善
  17. String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"; //连接SQL数据库的方法
  18. String URL="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_name"; //db_name为数据库名
  19. String Username="username"; //用户名
  20. String Password="password"; //密码
  21. Class.forName(Driver).new Instance(); //加载数据可驱动
  22. Connection con=DriverManager.getConnection(URL,UserName,Password); //
  23. Sysbase:
  24. String Driver="com.sybase.jdbc.SybDriver"; //驱动程序
  25. String URL="jdbc:Sysbase://localhost:5007/db_name"; //db_name为数据可名
  26. String Username="username"; //用户名
  27. String Password="password"; //密码
  28. Class.forName(Driver).newInstance();
  29. Connection con=DriverManager.getConnection(URL,Username,Password);
  30. Oracle(用thin模式):
  31. String Driver="oracle.jdbc.driver.OracleDriver"; //连接数据库的方法
  32. String URL="jdbc:oracle:thin:@loaclhost:1521:orcl"; //orcl为数据库的SID
  33. String Username="username"; //用户名
  34. String Password="password"; //密码
  35. Class.forName(Driver).newInstance(); //加载数据库驱动
  36. Connection con=DriverManager.getConnection(URL,Username,Password);
  37. PostgreSQL:
  38. String Driver="org.postgresql.Driver"; //连接数据库的方法
  39. String URL="jdbc:postgresql://localhost/db_name"; //db_name为数据可名
  40. String Username="username"; //用户名
  41. String Password="password"; //密码
  42. Class.forName(Driver).newInstance();
  43. Connection con=DriverManager.getConnection(URL,Username,Password);
  44. DB2
  45. String Driver="com.ibm.db2.jdbc.app.DB2.Driver"; //连接具有DB2客户端的Provider实例
  46. //String Driver="com.ibm.db2.jdbc.net.DB2.Driver"; //连接不具有DB2客户端的Provider实例
  47. String URL="jdbc:db2://localhost:5000/db_name"; //db_name为数据可名
  48. String Username="username"; //用户名
  49. String Password="password"; //密码
  50. Class.forName(Driver).newInstance();
  51. Connection con=DriverManager.getConnection(URL,Username,Password);
  52. Informix:
  53. String Driver="com.informix.jdbc.IfxDriver";
  54. String URL="jdbc:Informix-sqli://localhost:1533/db_name:INFORMIXSER=myserver"; //db_name为数据可名
  55. String Username="username"; //用户名
  56. String Password="password"; //密码
  57. Class.forName(Driver).newInstance();
  58. Connection con=DriverManager.getConnection(URL,Username,Password);
  59. JDBC-ODBC:
  60. String Driver="sun.jdbc.odbc.JdbcOdbcDriver";
  61. String URL="jdbc:odbc:dbsource"; //dbsource为数据源名
  62. String Username="username"; //用户名
  63. String Password="password"; //密码
  64. Class.forName(Driver).newInstance();
  65. Connection con=DriverManager.getConnection(URL,Username,Password);
  1. //点到线段的最短距离
  2.  
  3. private double pointToLine(int x1, int y1, int x2, int y2, int x0,
  4. int y0) {
  5. double space = 0;
  6. double a, b, c;
  7. a = lineSpace(x1, y1, x2, y2);// 线段的长度
  8. b = lineSpace(x1, y1, x0, y0);// (x1,y1)到点的距离
  9. c = lineSpace(x2, y2, x0, y0);// (x2,y2)到点的距离
  10. if (c <= 0.000001 || b <= 0.000001) {
  11. space = 0;
  12. return space;
  13. }
  14. if (a <= 0.000001) {
  15. space = b;
  16. return space;
  17. }
  18. if (c * c >= a * a + b * b) {
  19. space = b;
  20. return space;
  21. }
  22. if (b * b >= a * a + c * c) {
  23. space = c;
  24. return space;
  25. }
  26. double p = (a + b + c) / 2;// 半周长
  27. double s = Math.sqrt(p * (p - a) * (p - b) * (p - c));// 海伦公式求面积
  28. space = 2 * s / a;// 返回点到线的距离(利用三角形面积公式求高)
  29. return space;
  30. }
  31.  
  32. // 计算两点之间的距离
  33. private double lineSpace(int x1, int y1, int x2, int y2) {
  34. double lineLength = 0;
  35. lineLength = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2)
  36. * (y1 - y2));
  37. return lineLength;
  38.  
  39. }
  1. //java系统托盘的应用
  2.  
  3. package com.msg;
  4.  
  5. import java.applet.Applet;
  6. import java.applet.AudioClip;
  7. import java.awt.AWTException;
  8. import java.awt.Image;
  9. import java.awt.MenuItem;
  10. import java.awt.PopupMenu;
  11. import java.awt.SystemTray;
  12. import java.awt.TextArea;
  13. import java.awt.TrayIcon;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16. import java.awt.event.MouseAdapter;
  17. import java.awt.event.MouseEvent;
  18. import java.awt.event.WindowAdapter;
  19. import java.awt.event.WindowEvent;
  20. import java.net.MalformedURLException;
  21. import java.net.URL;
  22. import java.util.Date;
  23.  
  24. import javax.swing.ImageIcon;
  25. import javax.swing.JFrame;
  26. import javax.swing.SwingUtilities;
  27. import javax.swing.UIManager;
  28. import javax.swing.UnsupportedLookAndFeelException;
  29.  
  30. import org.jvnet.substance.skin.SubstanceBusinessBlueSteelLookAndFeel;
  31.  
  32. /**
  33. *
  34. * 创建闪动的托盘图像
  35. * @author Everest
  36. *
  37. */
  38. public class BickerTray extends JFrame implements Runnable {
  39.  
  40. private static final long serialVersionUID = -3115128552716619277L;
  41.  
  42. private SystemTray sysTray;// 当前操作系统的托盘对象
  43. private TrayIcon trayIcon;// 当前对象的托盘
  44.  
  45. private ImageIcon icon = null;
  46. private TextArea ta = null;
  47.  
  48. private static int count = 1; //记录消息闪动的次数
  49. private boolean flag = false; //是否有新消息
  50. private static int times = 1; //接收消息次数
  51.  
  52. public BickerTray() {
  53. this.createTrayIcon();// 创建托盘对象
  54. Image image = this.getToolkit().getImage(getRes("com/img/f32.gif"));
  55. this.setIconImage(image);
  56. init();
  57. }
  58.  
  59. public URL getRes(String str){
  60. return this.getClass().getClassLoader().getResource(str);
  61. }
  62.  
  63. /**
  64. * 初始化窗体的方法
  65. */
  66. public void init() {
  67. this.setTitle("消息盒子");
  68. ta = new TextArea("");
  69. ta.setEditable(false);
  70. this.add(ta);
  71. this.setSize(400, 400);
  72. //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  73. this.setLocationRelativeTo(null);
  74. // 添加窗口最小化事件,将托盘添加到操作系统的托盘
  75. /*this.addWindowListener(new WindowAdapter() {
  76. public void windowIconified(WindowEvent e) {
  77. addTrayIcon();
  78. }
  79. });*/
  80. addTrayIcon();
  81. this.setVisible(true);
  82. }
  83.  
  84. /**
  85. * 添加托盘的方法
  86. */
  87. public void addTrayIcon() {
  88. try {
  89. sysTray.add(trayIcon);// 将托盘添加到操作系统的托盘
  90. setVisible(false); // 使得当前的窗口隐藏
  91. new Thread(this).start();
  92. } catch (AWTException e1) {
  93. e1.printStackTrace();
  94. }
  95. }
  96.  
  97. /**
  98. * 创建系统托盘的对象 步骤:
  99. * 1,获得当前操作系统的托盘对象
  100. * 2,创建弹出菜单popupMenu
  101. * 3,创建托盘图标icon
  102. * 4,创建系统的托盘对象trayIcon
  103. */
  104. public void createTrayIcon() {
  105. sysTray = SystemTray.getSystemTray();// 获得当前操作系统的托盘对象
  106. icon = new ImageIcon(getRes("com/img/f17.gif"));// 托盘图标
  107. PopupMenu popupMenu = new PopupMenu();// 弹出菜单
  108. MenuItem mi = new MenuItem("打开");
  109. MenuItem exit = new MenuItem("退出");
  110. popupMenu.add(mi);
  111. popupMenu.add(exit);
  112. // 为弹出菜单项添加事件
  113. mi.addActionListener(new ActionListener() {
  114. public void actionPerformed(ActionEvent e) {
  115. ta.setText(ta.getText()+"\n==============================================\n 《通知》 今天下午4:00到大礼堂开会。 \n 第"+times+"次接收时间:"+ new Date().toLocaleString()); // 设置通知消息内容
  116. BickerTray.this.setExtendedState(JFrame.NORMAL);
  117. BickerTray.this.setVisible(true); // 显示窗口
  118. BickerTray.this.toFront(); //显示窗口到最前端
  119. flag = false; //消息打开了
  120. count = 0; times++;
  121. }
  122. });
  123. exit.addActionListener(new ActionListener() {
  124. public void actionPerformed(ActionEvent e) {
  125. System.exit(0);
  126. }
  127. });
  128. trayIcon = new TrayIcon(icon.getImage(), "消息盒子", popupMenu);
  129. /** 添加鼠标监听器,当鼠标在托盘图标上双击时,默认显示窗口 */
  130. trayIcon.addMouseListener(new MouseAdapter() {
  131. public void mouseClicked(MouseEvent e) {
  132. if (e.getClickCount() == 2) { // 鼠标双击
  133. ta.setText(ta.getText()+"\n==============================================\n 《通知》 今天下午4:00到大礼堂开会。 \n 第"+times+"次接收时间:"+ new Date().toLocaleString()); // 设置通知消息内容
  134. BickerTray.this.setExtendedState(JFrame.NORMAL);
  135. BickerTray.this.setVisible(true); // 显示窗口
  136. BickerTray.this.toFront();
  137. flag = false; //消息打开了
  138. count = 0; times++;
  139. }
  140. }
  141. });
  142. }
  143.  
  144. /**
  145. * 线程控制闪动
  146. */
  147. public void run() {
  148. while (true) {
  149. if(flag){ // 有新消息
  150. try {
  151. if(count == 1){
  152. // 播放消息提示音
  153. //AudioPlayer p = new AudioPlayer(getRes("file:com/sound/Msg.wav"));
  154. //p.play(); p.stop();
  155. try {
  156. AudioClip p = Applet.newAudioClip(new URL("file:sound/msg.wav"));
  157. p.play();
  158. } catch (MalformedURLException e) {
  159. e.printStackTrace();
  160. }
  161. }
  162. // 闪动消息的空白时间
  163. this.trayIcon.setImage(new ImageIcon("").getImage());
  164. Thread.sleep(500);
  165. // 闪动消息的提示图片
  166. this.trayIcon.setImage(icon.getImage());
  167. Thread.sleep(500);
  168. } catch (Exception e) {
  169. e.printStackTrace();
  170. }
  171. count++;
  172. }else{ // 无消息或是消息已经打开过
  173. this.trayIcon.setImage(icon.getImage());
  174. try {
  175. Thread.sleep(20000);
  176. flag = true;
  177. } catch (InterruptedException e) {
  178. e.printStackTrace();
  179. }
  180. }
  181. }
  182. }
  183.  
  184. /**
  185. * @param args
  186. */
  187. public static void main(String[] args) {
  188. JFrame.setDefaultLookAndFeelDecorated(true);
  189. try {
  190. UIManager.setLookAndFeel(new SubstanceBusinessBlueSteelLookAndFeel());
  191. } catch (UnsupportedLookAndFeelException e) {
  192. e.printStackTrace();
  193. }
  194.  
  195. SwingUtilities.invokeLater(new Runnable() {
  196. public void run() {
  197. new BickerTray();
  198. }
  199. });
  200. }
  201.  
  202. }
  1. //java dos输入输出
  2.  
  3. import java.util.*;
  4. public class DaoXu {
  5.  
  6. /**
  7. * @param args
  8. */
  9. public static void main(String[] args) {
  10. // TODO 自动生成方法存根
  11. System.out.println("请输入单个字符并回车: ");
  12. Scanner c = new Scanner(System.in);
  13.  
  14. String[] ch = new String[5];
  15.  
  16. for(int i=0; i<5; i++){
  17. ch[i] = c.next();
  18. }
  19.  
  20. //Arrays.sort(ch);
  21.  
  22. System.out.print("倒序输出: ");
  23. for (int j = ch.length-1; j >= 0; j--) {
  24. System.out.print(ch[j]+" ");
  25. }
  26. }
  27. }
  1. //java日期处理bean
  2.  
  3. import java.text.ParsePosition;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Calendar;
  6. import java.util.Date;
  7. import java.util.GregorianCalendar;
  8. import java.util.regex.Pattern;
  9.  
  10. import org.apache.commons.logging.Log;
  11. import org.apache.commons.logging.LogFactory;
  12.  
  13. public class DateUtil {
  14. protected static Log logger = LogFactory.getLog(DateUtil.class);
  15.  
  16. // 格式:年-月-日 小时:分钟:秒
  17. public static final String FORMAT_ONE = "yyyy-MM-dd HH:mm:ss";
  18.  
  19. // 格式:年-月-日 小时:分钟
  20. public static final String FORMAT_TWO = "yyyy-MM-dd HH:mm";
  21.  
  22. // 格式:年月日 小时分钟秒
  23. public static final String FORMAT_THREE = "yyyyMMdd-HHmmss";
  24.  
  25. // 格式:年-月-日
  26. public static final String LONG_DATE_FORMAT = "yyyy-MM-dd";
  27.  
  28. // 格式:月-日
  29. public static final String SHORT_DATE_FORMAT = "MM-dd";
  30.  
  31. // 格式:小时:分钟:秒
  32. public static final String LONG_TIME_FORMAT = "HH:mm:ss";
  33.  
  34. //格式:年-月
  35. public static final String MONTG_DATE_FORMAT = "yyyy-MM";
  36.  
  37. // 年的加减
  38. public static final int SUB_YEAR = Calendar.YEAR;
  39.  
  40. // 月加减
  41. public static final int SUB_MONTH = Calendar.MONTH;
  42.  
  43. // 天的加减
  44. public static final int SUB_DAY = Calendar.DATE;
  45.  
  46. // 小时的加减
  47. public static final int SUB_HOUR = Calendar.HOUR;
  48.  
  49. // 分钟的加减
  50. public static final int SUB_MINUTE = Calendar.MINUTE;
  51.  
  52. // 秒的加减
  53. public static final int SUB_SECOND = Calendar.SECOND;
  54.  
  55. static final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四",
  56. "星期五", "星期六" };
  57.  
  58. @SuppressWarnings("unused")
  59. private static final SimpleDateFormat timeFormat = new SimpleDateFormat(
  60. "yyyy-MM-dd HH:mm:ss");
  61.  
  62. public DateUtil() {
  63. }
  64.  
  65. /**
  66. * 把符合日期格式的字符串转换为日期类型
  67. */
  68. public static java.util.Date stringtoDate(String dateStr, String format) {
  69. Date d = null;
  70. SimpleDateFormat formater = new SimpleDateFormat(format);
  71. try {
  72. formater.setLenient(false);
  73. d = formater.parse(dateStr);
  74. } catch (Exception e) {
  75. // log.error(e);
  76. d = null;
  77. }
  78. return d;
  79. }
  80.  
  81. /**
  82. * 把符合日期格式的字符串转换为日期类型
  83. */
  84. public static java.util.Date stringtoDate(String dateStr, String format,
  85. ParsePosition pos) {
  86. Date d = null;
  87. SimpleDateFormat formater = new SimpleDateFormat(format);
  88. try {
  89. formater.setLenient(false);
  90. d = formater.parse(dateStr, pos);
  91. } catch (Exception e) {
  92. d = null;
  93. }
  94. return d;
  95. }
  96.  
  97. /**
  98. * 把日期转换为字符串
  99. */
  100. public static String dateToString(java.util.Date date, String format) {
  101. String result = "";
  102. SimpleDateFormat formater = new SimpleDateFormat(format);
  103. try {
  104. result = formater.format(date);
  105. } catch (Exception e) {
  106. // log.error(e);
  107. }
  108. return result;
  109. }
  110.  
  111. /**
  112. * 获取当前时间的指定格式
  113. */
  114. public static String getCurrDate(String format) {
  115. return dateToString(new Date(), format);
  116. }
  117.  
  118. public static String dateSub(int dateKind, String dateStr, int amount) {
  119. Date date = stringtoDate(dateStr, FORMAT_ONE);
  120. Calendar calendar = Calendar.getInstance();
  121. calendar.setTime(date);
  122. calendar.add(dateKind, amount);
  123. return dateToString(calendar.getTime(), FORMAT_ONE);
  124. }
  125.  
  126. /**
  127. * 两个日期相减
  128. * @return 相减得到的秒数
  129. */
  130. public static long timeSub(String firstTime, String secTime) {
  131. long first = stringtoDate(firstTime, FORMAT_ONE).getTime();
  132. long second = stringtoDate(secTime, FORMAT_ONE).getTime();
  133. return (second - first) / 1000;
  134. }
  135.  
  136. /**
  137. * 获得某月的天数
  138. */
  139. public static int getDaysOfMonth(String year, String month) {
  140. int days = 0;
  141. if (month.equals("1") || month.equals("3") || month.equals("5")
  142. || month.equals("7") || month.equals("8") || month.equals("10")
  143. || month.equals("12")) {
  144. days = 31;
  145. } else if (month.equals("4") || month.equals("6") || month.equals("9")
  146. || month.equals("11")) {
  147. days = 30;
  148. } else {
  149. if ((Integer.parseInt(year) % 4 == 0 && Integer.parseInt(year) % 100 != 0)
  150. || Integer.parseInt(year) % 400 == 0) {
  151. days = 29;
  152. } else {
  153. days = 28;
  154. }
  155. }
  156.  
  157. return days;
  158. }
  159.  
  160. /**
  161. * 获取某年某月的天数
  162. */
  163. public static int getDaysOfMonth(int year, int month) {
  164. Calendar calendar = Calendar.getInstance();
  165. calendar.set(year, month - 1, 1);
  166. return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
  167. }
  168.  
  169. /**
  170. * 获得当前日期
  171. */
  172. public static int getToday() {
  173. Calendar calendar = Calendar.getInstance();
  174. return calendar.get(Calendar.DATE);
  175. }
  176.  
  177. /**
  178. * 获得当前月份
  179. */
  180. public static int getToMonth() {
  181. Calendar calendar = Calendar.getInstance();
  182. return calendar.get(Calendar.MONTH) + 1;
  183. }
  184.  
  185. /**
  186. * 获得当前年份
  187. */
  188. public static int getToYear() {
  189. Calendar calendar = Calendar.getInstance();
  190. return calendar.get(Calendar.YEAR);
  191. }
  192.  
  193. /**
  194. * 返回日期的天
  195. */
  196. public static int getDay(Date date) {
  197. Calendar calendar = Calendar.getInstance();
  198. calendar.setTime(date);
  199. return calendar.get(Calendar.DATE);
  200. }
  201.  
  202. /**
  203. * 返回日期的年
  204. */
  205. public static int getYear(Date date) {
  206. Calendar calendar = Calendar.getInstance();
  207. calendar.setTime(date);
  208. return calendar.get(Calendar.YEAR);
  209. }
  210.  
  211. /**
  212. * 返回日期的月份,1-12
  213. */
  214. public static int getMonth(Date date) {
  215. Calendar calendar = Calendar.getInstance();
  216. calendar.setTime(date);
  217. return calendar.get(Calendar.MONTH) + 1;
  218. }
  219.  
  220. /**
  221. * 计算两个日期相差的天数,如果date2 > date1 返回正数,否则返回负数
  222. */
  223. public static long dayDiff(Date date1, Date date2) {
  224. return (date2.getTime() - date1.getTime()) / 86400000;
  225. }
  226.  
  227. /**
  228. * 比较两个日期的年差
  229. */
  230. public static int yearDiff(String before, String after) {
  231. Date beforeDay = stringtoDate(before, LONG_DATE_FORMAT);
  232. Date afterDay = stringtoDate(after, LONG_DATE_FORMAT);
  233. return getYear(afterDay) - getYear(beforeDay);
  234. }
  235.  
  236. /**
  237. * 比较指定日期与当前日期的差
  238. */
  239. public static int yearDiffCurr(String after) {
  240. Date beforeDay = new Date();
  241. Date afterDay = stringtoDate(after, LONG_DATE_FORMAT);
  242. return getYear(beforeDay) - getYear(afterDay);
  243. }
  244.  
  245. /**
  246. * 比较指定日期与当前日期的差
  247. */
  248. public static long dayDiffCurr(String before) {
  249. Date currDate = DateUtil.stringtoDate(currDay(), LONG_DATE_FORMAT);
  250. Date beforeDate = stringtoDate(before, LONG_DATE_FORMAT);
  251. return (currDate.getTime() - beforeDate.getTime()) / 86400000;
  252.  
  253. }
  254.  
  255. /**
  256. * 获取每月的第一周
  257. */
  258. public static int getFirstWeekdayOfMonth(int year, int month) {
  259. Calendar c = Calendar.getInstance();
  260. c.setFirstDayOfWeek(Calendar.SATURDAY); // 星期天为第一天
  261. c.set(year, month - 1, 1);
  262. return c.get(Calendar.DAY_OF_WEEK);
  263. }
  264. /**
  265. * 获取每月的最后一周
  266. */
  267. public static int getLastWeekdayOfMonth(int year, int month) {
  268. Calendar c = Calendar.getInstance();
  269. c.setFirstDayOfWeek(Calendar.SATURDAY); // 星期天为第一天
  270. c.set(year, month - 1, getDaysOfMonth(year, month));
  271. return c.get(Calendar.DAY_OF_WEEK);
  272. }
  273.  
  274. /**
  275. * 获得当前日期字符串,格式"yyyy_MM_dd_HH_mm_ss"
  276. *
  277. * @return
  278. */
  279. public static String getCurrent() {
  280. Calendar cal = Calendar.getInstance();
  281. cal.setTime(new Date());
  282. int year = cal.get(Calendar.YEAR);
  283. int month = cal.get(Calendar.MONTH) + 1;
  284. int day = cal.get(Calendar.DAY_OF_MONTH);
  285. int hour = cal.get(Calendar.HOUR_OF_DAY);
  286. int minute = cal.get(Calendar.MINUTE);
  287. int second = cal.get(Calendar.SECOND);
  288. StringBuffer sb = new StringBuffer();
  289. sb.append(year).append("_").append(StringUtil.addzero(month, 2))
  290. .append("_").append(StringUtil.addzero(day, 2)).append("_")
  291. .append(StringUtil.addzero(hour, 2)).append("_").append(
  292. StringUtil.addzero(minute, 2)).append("_").append(
  293. StringUtil.addzero(second, 2));
  294. return sb.toString();
  295. }
  296.  
  297. /**
  298. * 获得当前日期字符串,格式"yyyy-MM-dd HH:mm:ss"
  299. *
  300. * @return
  301. */
  302. public static String getNow() {
  303. Calendar today = Calendar.getInstance();
  304. return dateToString(today.getTime(), FORMAT_ONE);
  305. }
  306.  
  307. /**
  308. * 判断日期是否有效,包括闰年的情况
  309. *
  310. * @param date
  311. * YYYY-mm-dd
  312. * @return
  313. */
  314. public static boolean isDate(String date) {
  315. StringBuffer reg = new StringBuffer(
  316. "^((\\d{2}(([02468][048])|([13579][26]))-?((((0?");
  317. reg.append("[13578])|(1[02]))-?((0?[1-9])|([1-2][0-9])|(3[01])))");
  318. reg.append("|(((0?[469])|(11))-?((0?[1-9])|([1-2][0-9])|(30)))|");
  319. reg.append("(0?2-?((0?[1-9])|([1-2][0-9])))))|(\\d{2}(([02468][12");
  320. reg.append("35679])|([13579][01345789]))-?((((0?[13578])|(1[02]))");
  321. reg.append("-?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))");
  322. reg.append("-?((0?[1-9])|([1-2][0-9])|(30)))|(0?2-?((0?[");
  323. reg.append("1-9])|(1[0-9])|(2[0-8]))))))");
  324. Pattern p = Pattern.compile(reg.toString());
  325. return p.matcher(date).matches();
  326. }
  1. //java访问资源文件
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.util.Properties;
  6.  
  7. public class PropertyEditor {
  8. public static void main(String[] args) throws Exception {
  9. Properties prop = new Properties();// 属性集合对象
  10. FileInputStream fis = new FileInputStream("prop.properties");// 属性文件输入流 (相对于根目录下的文件名,要加上包名 “src/prop.properties”)
  11. prop.load(fis);// 将属性文件流装载到Properties对象中
  12. fis.close();// 关闭流
  13.  
  14. // 获取属性值,sitename已在文件中定义
  15. System.out.println("获取属性值:sitename=" + prop.getProperty("sitename"));
  16. // 获取属性值,country未在文件中定义,将在此程序中返回一个默认值,但并不修改属性文件
  17. System.out.println("获取属性值:country=" + prop.getProperty("country", "中国"));
  18.  
  19. // 修改sitename的属性值
  20. prop.setProperty("sitename", "中国");
  21. // 添加一个新的属性studio
  22. prop.setProperty("studio", "Boxcode Studio");
  23. // 文件输出流
  24. FileOutputStream fos = new FileOutputStream("prop.properties");
  25. // 将Properties集合保存到流中
  26. prop.store(fos, "Copyright (c) Boxcode Studio");
  27. fos.close();// 关闭流
  28. }
  29. }
  1. //java自定义按钮外观
  2.  
  3. import java.awt.FlowLayout;
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. import javax.swing.UIManager;
  7. import javax.swing.plaf.synth.SynthLookAndFeel;
  8.  
  9. public class MyButton {
  10. JFrame frame = new JFrame("Test Buttons");
  11. JButton jButton = new JButton("JButton"); // 按钮
  12. public MyButton() {
  13. frame.setLayout(new FlowLayout());
  14. frame.getContentPane().add(jButton);
  15. }
  16. public void show() {
  17. frame.pack();
  18. frame.show();
  19. }
  20. public static void main(String[] args) {
  21. MyButton tb = new MyButton();
  22. tb.show();
  23. SynthLookAndFeel slf = new SynthLookAndFeel();
  24. try {
  25. slf.load(MyButton.class.getResourceAsStream("mybutton.xml"), MyButton.class);
  26. UIManager.setLookAndFeel(slf);
  27. } catch (Exception e) {
  28. e.printStackTrace();
  29. return;
  30. }
  31.  
  32. }
  33. }
  1. //java jdbc数据库连接
  2.  
  3. import java.io.InputStream;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import java.sql.Statement;
  9. import java.util.Properties;
  10.  
  11. public class JDBConnection {
  12. public Connection conn = null; // 声明Connection对象的实例
  13. public Statement stmt = null; // 声明Statement对象的实例
  14. public ResultSet rs = null; // 声明ResultSet对象的实例
  15.  
  16. private static String dbClassName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";//定义保存数据库驱动的变量
  17. private static String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=DB_ATM";
  18. private static String dbUser = "sa";
  19. private static String dbPwd = "sa";
  20.  
  21. public JDBConnection(String propertyFileName) {// 带属性文件名的构造方法
  22. Properties prop = new Properties();// 属性集合对象
  23. InputStream is = null;
  24. try {
  25. is = JDBConnection.class.getClassLoader().getResourceAsStream(
  26. propertyFileName);// 属性文件输入流
  27. // is = new FileInputStream("src/" + propertyFileName);
  28. prop.load(is);// 将属性文件流装载到Properties对象中
  29. is.close();// 关闭流
  30. dbClassName = prop.getProperty("dbClassName");
  31. dbUrl = prop.getProperty("dbUrl");
  32. dbUser = prop.getProperty("dbUser");
  33. dbPwd = prop.getProperty("dbPwd");
  34. } catch (Exception e) {
  35. System.out.println("属性文件 " + propertyFileName + " 打开失败!");
  36. }
  37. try {
  38.  
  39. Class.forName(dbClassName);// 1.注册驱动
  40. } catch (ClassNotFoundException e) {
  41. e.printStackTrace();
  42. }
  43. }
  44.  
  45. public JDBConnection() {// 默认的不带参数的构造函数
  46. try {
  47.  
  48. Class.forName(dbClassName);// 1.注册驱动
  49. } catch (ClassNotFoundException e) {
  50. e.printStackTrace();
  51. }
  52. }
  53.  
  54. public static Connection getConnection() {
  55. Connection conn = null;
  56. try {
  57. // Class.forName(dbClassName);// 1.注册驱动
  58. conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);//2.建立与数据库的链接
  59. } catch (Exception ee) {
  60. ee.printStackTrace();
  61. }
  62. if (conn == null) {
  63. System.err
  64. .println("警告: DbConnectionManager.getConnection() 获得数据库链接失败.\r\n\r\n链接类型:"
  65. + dbClassName
  66. + "\r\n链接位置:"
  67. + dbUrl
  68. + "\r\n用户/密码"
  69. + dbUser + "/" + dbPwd);
  70. }
  71. return conn;
  72. }
  73.  
  74. /*
  75. * 功能:执行查询语句
  76. */
  77. public ResultSet executeQuery(String sql) {
  78. try { // 捕捉异常
  79. conn = getConnection(); // 调用getConnection()方法构造Connection对象的一个实例conn
  80. stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,//3.创建语句
  81. ResultSet.CONCUR_READ_ONLY);
  82. rs = stmt.executeQuery(sql);//4.执行查询
  83. } catch (SQLException ex) {
  84. System.err.println(ex.getMessage()); // 输出异常信息
  85. }
  86. return rs; // 返回结果集对象 5.结果处理
  87. }
  88.  
  89. /*
  90. * 功能:执行更新操作
  91. */
  92. public int executeUpdate(String sql) {
  93. int result = 0; // 定义保存返回值的变量
  94. try { // 捕捉异常
  95. conn = getConnection(); // 调用getConnection()方法构造Connection对象的一个实例conn
  96. stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
  97. ResultSet.CONCUR_READ_ONLY);
  98. result = stmt.executeUpdate(sql); // 执行更新操作
  99. } catch (SQLException ex) {
  100. result = 0; // 将保存返回值的变量赋值为0
  101. }
  102. return result; // 返回保存返回值的变量
  103. }
  104.  
  105. /*
  106. * 功能:关闭数据库的连接
  107. */
  108. public void close() {//6.释放资源
  109. try { // 捕捉异常
  110. try {
  111. if (rs != null) { // 当ResultSet对象的实例rs不为空时
  112. rs.close(); // 关闭ResultSet对象
  113. }
  114. } finally {
  115. try {
  116. if (stmt != null) { // 当Statement对象的实例stmt不为空时
  117. stmt.close(); // 关闭Statement对象
  118. }
  119. } finally {
  120. if (conn != null) { // 当Connection对象的实例conn不为空时
  121. conn.close(); // 关闭Connection对象
  122. }
  123. }
  124. }
  125. } catch (Exception e) {
  126. e.printStackTrace(System.err); // 输出异常信息
  127. }
  128. }
  129.  
  130. }
  1. //java访问xml文件
  2.  
  3. import java.io.*;
  4. import javax.xml.parsers.DocumentBuilder;
  5. import javax.xml.parsers.DocumentBuilderFactory;
  6. import org.w3c.dom.Document;
  7. import org.w3c.dom.Element;
  8. import org.w3c.dom.Node;
  9. import org.w3c.dom.NodeList;
  10.  
  11. public class xmljava
  12. {
  13.  
  14. public static void main(String args[])
  15. {
  16. Element element=null;
  17. File f =new File("a.xml");
  18. DocumentBuilder db=null; //documentBuilder为抽象不能直接实例化(将XML文件转换为DOM文件)
  19. DocumentBuilderFactory dbf=null;
  20. try{
  21.  
  22. dbf= DocumentBuilderFactory.newInstance(); //返回documentBuilderFactory对象
  23. db =dbf.newDocumentBuilder();//返回db对象用documentBuilderFatory对象获得返回documentBuildr对象
  24.  
  25. Document dt= db.parse(f); //得到一个DOM并返回给document对象
  26. element = dt.getDocumentElement();//得到一个elment根元素
  27.  
  28. System.out.println("根元素:"+element.getNodeName()); //获得根节点
  29.  
  30. NodeList childNodes =element.getChildNodes() ; // 获得根元素下的子节点
  31.  
  32. for (int i = 0; i < childNodes.getLength(); i++) // 遍历这些子节点
  33.  
  34. {
  35. Node node1 = childNodes.item(i); // childNodes.item(i); 获得每个对应位置i的结点
  36.  
  37. if ("Account".equals(node1.getNodeName()))
  38. {
  39. // 如果节点的名称为"Account",则输出Account元素属性type
  40. System.out.println("\r\n找到一篇账号. 所属区域: " + node1.getAttributes().getNamedItem ("type").getNodeValue() + ". ");
  41. NodeList nodeDetail = node1.getChildNodes(); // 获得<Accounts>下的节点
  42. for (int j = 0; j < nodeDetail.getLength(); j++)
  43. { // 遍历<Accounts>下的节点
  44. Node detail = nodeDetail.item(j); // 获得<Accounts>元素每一个节点
  45. if ("code".equals(detail.getNodeName())) // 输出code
  46. System.out.println("卡号: " + detail.getTextContent());
  47. else if ("pass".equals(detail.getNodeName())) // 输出pass
  48. System.out.println("密码: " + detail.getTextContent());
  49. else if ("name".equals(detail.getNodeName())) // 输出name
  50. System.out.println("姓名: " + detail.getTextContent());
  51. else if ("money".equals(detail.getNodeName())) // 输出money
  52. System.out.println("余额: "+ detail.getTextContent());
  53.  
  54. }
  55. }
  56.  
  57. }
  58. }
  59.  
  60. catch(Exception e){System.out.println(e);}
  61.  
  62. }
  63. }
  64.  
  65. //XML CODE FILE
  66.  
  67. <?xml version="1.0" encoding="gbk"?>
  68. <Accounts>
  69. <Account type="by0003">
  70. <code>100001</code>
  71. <pass>123</pass>
  72. <name>李四</name>
  73. <money>1000000.00</money>
  74. </Account>
  75. <Account type="hz0001">
  76. <code>100002</code>
  77. <pass>123</pass>
  78. <name>张三</name>
  79. <money>1000.00</money>
  80. </Account>
  81. </Accounts>

java常用用代码的更多相关文章

  1. java常用公共代码二之分页代码的实现

    在项目中,我们经常会写到一些公共的代码,来让开发人员调用,减少代码重复,下面,我就将一些常用到的公共类贴出来和大家分享!! 二.分页代码实现:在项目中,分页是一个项目中必不可少的,它可以防止我们从数据 ...

  2. java 常用模块代码

    1.文件的读写操作 (1)进行读操作 import java.io.BufferedReader; import java.io.FileNotFoundException; import java. ...

  3. Java常用基础代码

    1.加载properties文件 Properties properties = new Properties();  properties.load(Properties.class.getReso ...

  4. Java常用代码段 - 未完待续

    记录一些自己写项目常用的代码段. 格式化常用日期格式 Date date = new Date(System.currentTimeMillis()); DateFormat d3 = DateFor ...

  5. java常用英文解释

    java常用名词解释: OO: object-oriented ,面向对象 OOP:object-oriented programming,面向对象编程 Author:JCC Object:对象JDK ...

  6. JAVA常用的XML解析方法

    转并总结自(java xml) JAVA常用的解析xml的方法有四种,分别是DOM,JAX,JDOM,DOM4j xml文件 <?xml version="1.0" enco ...

  7. java基础3.0:Java常用API

    本篇介绍Java基础中常用API使用,当然只是简单介绍,围绕重要知识点引入,巩固开发知识,深入了解每个API的使用,查看JavaAPI文档是必不可少的. 一.java.lang包下的API Java常 ...

  8. java开发功能代码汇总

    多文件上传 http://smotive.iteye.com/blog/1903606 java 常用代码 Struts2 前后台(Action ,jsp)传值.取值 Action public Li ...

  9. 分享非常有用的Java程序(关键代码)(八)---Java InputStream读取网络响应Response数据的方法!(重要)

    原文:分享非常有用的Java程序(关键代码)(八)---Java InputStream读取网络响应Response数据的方法!(重要) Java InputStream读取数据问题 ======== ...

随机推荐

  1. vim下缩进及高亮设置

    1.配置文件的位置 在目录 /etc/ 下面,有个名为vimrc的文件,这是系统中公共的vim配置文件,对所有用户都有效.而在每个用户的主目录下,都可以自己建立私有的配置文件,命名为:“.vimrc” ...

  2. F - Wormholes

    题目大意: 农民约翰在农场散步的时候发现农场有大量的虫洞,这些虫洞是非常特别的因为它们都是单向通道,为了方便现在把约翰的农田划分成N快区域,M条道路,W的虫洞. 约翰是时空旅行的粉丝,他希望这样做,在 ...

  3. Windows下svn客户端和服务器的安装使用

    svn,全称subversion, 是目前用的较多的开源的版本管理工具.相信有些经历的程序员应该都听说过它. 通常的svn服务器是搭建在Linux中,不过如果作为个人或者单个小组使用的话,就可以把sv ...

  4. FC和SCSI

    IDE(Integrated Drive Electronics)即"电子集成驱动器",它的本意是指把"硬盘控制器"与"盘体"集成在一起的硬 ...

  5. oracle 32位和64位的问题

  6. android开发launcher

    1. launcher是桌面应用程序 一. android.intent.category.LAUNCHER与android.intent.category.HOME的差别?      android ...

  7. git的一些概念和技巧

    1. 分支代表最后三个commit(即HEAD, HEAD^和HEAD~2),前一个commit,也用HEAD~1 2. 查看一个文件的改动历史git log (--pretty=oneline) - ...

  8. linux的文本管道连接处理技巧

    举例1: strace -f -e open cpp Hello.cpp -o /dev/null 2>&1 | grep -v ENOENT | awk '{print $3}' 1) ...

  9. 《Android开发艺术探索》读书笔记 (3) 第3章 View的事件体系

    本节和<Android群英传>中的第五章Scroll分析有关系,建议先阅读该章的总结 第3章 View的事件体系 3.1 View基本知识 (1)view的层次结构:ViewGroup也是 ...

  10. Sql语句 不支持中文 国外数据库

    由于老美的不支持中文 SQL 语句第一:字段类型改为nvarchar,ntext 第二:强制转化 N update dbo.Role set rolename=N'普通用户' update dbo.T ...