/**
- 用输入输出流开启连接,添加参数,然后获取参数值
- 向一个文件中写入内容
- 从文件中读出内容
- 从缓冲读入流中读取内容然后处理
*/
//用输入输出流开启连接,添加参数,然后获取参数值
URL url = new URL(fileDownloadPath);
URLConnection connection = url.openConnection();
connection.setDoOutput(true);
PrintWriter outStream = new PrintWriter(connection.getOutputStream());
outStream.print("username=" + username);//hkaws_file_download
outStream.print("&password=" + password);//12345678
outStream.print("&xml=" + xml); //<?xml version="1.0" encoding="UTF-8" ?>
outStream.print("&source=" + PrintInfo.SOURCE_WEB);//WEB
outStream.print("&token=" + token);//0
outStream.print("&queue_category=" + queueCategory); // LABEL
outStream.print("&agent_code=" + agentCode);//300693
outStream.close();
InputStream in = connection.getInputStream(); ==> jump to print_label_now.jsp
String newUsername = request.getParameter("username");
String newPassword = request.getParameter("password");
String source = request.getParameter("source");
String token = request.getParameter("token");
String xml = request.getParameter("xml");
String queueCategory = request.getParameter("queue_category");
String agentCode = request.getParameter("agent_code");
if (agentCode == null && xml != null && !"".equals(xml)) {
agentCode = getValueByAttribute(xml, "agent_code");
}
--------------------------------
//向一个文件中写入内容
public void generateFeed() throws IOException{
ArrayList result = generateLines();
FileWriter writer = new FileWriter(filePath,false);
PrintWriter pw = new PrintWriter(writer);
for (int i=0;i<result.size();i++){
String line = (String)result.get(i);
pw.println(line);
//dos.writeChars(line);
}
pw.close();
writer.close();
}
//向一个文件中写入内容
FileOutputStream out = new FileOutputStream(logFileName);
PrintWriter log = new PrintWriter(out);
String line = "";
String errMsg = "";
log.write((new Date()).toString() + " ERROR in uploading report(" + reportUploaderVO.getFileName()
+ ", AgentCode : " + reportUploaderVO.getAgentCode() + ")\n");
log.write((new Date()).toString() + " " + errMsg);
log.close();
//写入对象到一个文件
ObjectOutputStream feed = new ObjectOutputStream(new FileOutputStream(noteFile));
feed.writeObject(paReports);
feed.close();
//从一个文件中读出对象
String feedFileName = args[0];
String logFileName = args[1];
ObjectInputStream in = new ObjectInputStream(new FileInputStream(feedFileName));
ArrayList arrayList = (ArrayList)in.readObject();
File file = new File(logFileName);
if (file.exists()){
file.delete();
}
sql.delete(0, sql.length());
----------------------------------------------------
BufferedReader br = new BufferedReader(new FileReader(agentFeedPath));
while ((line = br.readLine()) != null){
if (line.startsWith("HEADER") || line.startsWith("TRAILER"))
continue;
agentCode = line.substring(0, 6).trim();
agent = new AgentIdentification();
agent.setAgentCode(agentCode);
agent.setAgentName(line.substring(6, 36).trim());
agent.setUnitCode(line.substring(36, 41).trim());
agent.setBranchCode(line.substring(41, 46).trim());
agent.setBranchHead(line.substring(46, 76).trim());
agent.setBranchName(line.substring(76, 106).trim());
agent.setAgentEmail(line.substring(106, 166).trim());
if (cond == BY_AGENT){
agentTable.put(agentCode, agent);
}
branch = (AgentIdentification)agentTable.get(agent.getBranchCode());
}