admin 管理员组

文章数量: 1184232


2024年3月7日发(作者:tcp和socket区别)

JohnB12MaryA11SimonA18

package ser;import ;import ntBuilder;import ntBuilderFactory;import nt;import t;import ;import st;public class XMLParser {public void getAllUserNames(String fileName) {try {DocumentBuilderFactory dbf = tance();DocumentBuilder db = umentBuilder();File file = new File(fileName);if (()) {Document doc = (file);Element docEle = umentElement();// Print root element of the n(“Root element of the document: ”+ eName());NodeList studentList = mentsByTagName(“student”);// Print total student elements in n(“Total students: ” + gth());if (studentList != null && gth() > 0) {for (int i = 0; i < gth(); i++) {Node node = (i);if (eType() == T_NODE) {n(“=====================”);Element e = (Element) node;NodeList nodeList = mentsByTagName(“name”);n(“Name: ”+ (0).getChildNodes().item(0).getNodeValue());nodeList = mentsByTagName(“grade”);n(“Grade: ”+ (0).getChildNodes().item(0).getNodeValue());nodeList = mentsByTagName(“age”);n(“Age: ”+ (0).getChildNodes().item(0).getNodeValue());}}} else {(1);}}} catch (Exception e) {n(e);}}public static void main(String[] args) {XMLParser parser = new XMLParser();UserNames(“c:”);}}17. 把 Array 转换成 Map

import ;import tils;public class Main {public static void main(String[] args) {String[][] countries = { { ”United States”, ”New York” }, { ”United Kingdom”, ”London” },{ ”Netherland”, ”Amsterdam” }, { ”Japan”, ”Tokyo” }, { ”France”, ”Paris” } };Map countryCapitals = (countries);n(“Capital of Japan is ” + (“Japan”));n(“Capital of France is ” + (“France”));}}18. 发送邮件import .*;import et.*;import .*;public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException{boolean debug = false;//Set the host smtp addressProperties props = new Properties();(“”, ””);// create some properties and get the default SessionSession session = aultInstance(props, null);ug(debug);// create a messageMessage msg = new MimeMessage(session);// set the from and to addressInternetAddress addressFrom = new InternetAddress(from);m(addressFrom);InternetAddress[] addressTo = new InternetAddress[];for (int i = 0; i < ; i++){addressTo[i] = new InternetAddress(recipients[i]);}ipients(, addressTo);// Optional : You can also set your custom headers in the Email if you der(“MyHeaderName”, ”myHeaderValue”);// Setting the Subject and Content ject(subject);tent(message, ”text/plain”);(msg);}19. 发送代数据的HTTP 请求


本文标签: 数据 发送 请求