`
wei_jing
  • 浏览: 39334 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

一些常用的收集

JSP 
阅读更多

读文件的内容:
	public Set getExceptionalUsers() {
		Set users = new HashSet();
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader(new File(exceptionalFile)));
			String username = "";
			while ((username = reader.readLine()) != null && username != "") {
				users.add(username);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (reader != null) {
					reader.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			reader = null;
		}
		return users;
	}



http请求
private static void connect(String urlString) {
		try {
			URL url = new URL(urlString);
			connection = url.openConnection();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static String readContents(String urlString) {
		connect(urlString);
		BufferedReader in = null;
		StringBuffer sb = null;
		String inline = "";
		try {
			in = new BufferedReader(new InputStreamReader(connection
					.getInputStream()));
			sb = new StringBuffer();

			while ((inline = in.readLine()) != null) {
				sb.append(inline);
			}
			inline = sb.toString().trim();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return inline;
	}
----------------------------------------------
 URL URLquery = new URL(firstURL); //调用查询接口
            BufferedReader Read = new BufferedReader(new InputStreamReader(URLquery.openStream()));
            System.out.println("read the jsp return result");
            while ( (Line = Read.readLine()) != null) { //获得接口调用结果
                 Lines += Line;
            }
            Read.close();



关于时间:
SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd");
    	String formatDate = format.format(new Date());
    	System.out.println(formatDate);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics