Tôi đang cố gắng viết kết quả của phương thức sau vào trang web. Tôi nghĩ rằng có thể làm, tôi chỉ gặp khó khăn trong việc tìm ra chính xác cách làm điều đó. Bất kỳ trợ giúp sẽ được rất đánh giá cao. Cảm ơn.
... System.out.println("Final Register"); for (int i=0; i < ch.length; i++) { System.out.println(cd.getDenomLiteralAt(i)+" "+cd.getDenomNumAt(i)); } } ...Hỏi ngày 25 tháng 7 năm 2012 lúc 5:35Jul 25, 2012 at 5:35
Kerry Gkerry gKerry G
9014 Huy hiệu vàng12 Huy hiệu bạc21 Huy hiệu đồng4 gold badges12 silver badges21 bronze badges
3
Trong Java có nhiều cách để ghi dữ liệu trên một tệp. Để viết dữ liệu văn bản, cách dễ nhất là sử dụng một bộ đệm.
Xem bản demo dưới đây
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here }Đã trả lời ngày 25 tháng 7 năm 2012 lúc 6:19Jul 25, 2012 at 6:19
MavroscymavroscyMaVRoSCy
17.5K14 Huy hiệu vàng79 Huy hiệu bạc122 Huy hiệu đồng14 gold badges79 silver badges122 bronze badges
3
Tất cả những gì bạn cần làm là biết đường dẫn đến tệp HTML công khai của máy chủ web của bạn.
Chạy mã Java và ghi vào một tệp bên dưới đường dẫn đó. Nó không khác gì viết vào bất kỳ tệp nào khác trên máy, ngoại trừ cái này mà thế giới có thể thấy. Chỉ có điều là, nếu Java của bạn sẽ tạo tệp, bạn nên chắc chắn đặt các quyền bảo vệ đủ cho tệp. 0755 là an toàn vừa phải.
Đã trả lời ngày 25 tháng 7 năm 2012 lúc 5:38Jul 25, 2012 at 5:38
DandanDan
3.1561 Huy hiệu vàng 30 Huy hiệu bạc49 Huy hiệu đồng1 gold badge30 silver badges49 bronze badges
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Approaches:
- Bàn luận
- HTML là cốt lõi của web, tất cả các trang bạn thấy trên Internet là HTML, cho dù chúng được tạo động bởi JavaScript, JSP, PHP, ASP hoặc bất kỳ công nghệ web nào khác. Trình duyệt của bạn thực sự phân tích HTML và hiển thị nó cho bạn nhưng nếu chúng tôi cần phân tích một tài liệu HTML và tìm một số phần tử, thẻ, thuộc tính hoặc kiểm tra xem một phần tử cụ thể có tồn tại hay không. Trong Java, chúng ta có thể trích xuất nội dung HTML và có thể phân tích tài liệu HTML.
Sử dụng FilereaderThe library called the FileReader which provides the way to read any File irrespective of any Extension. The way to append the HTML lines to the String Builder is as follows:
- Sử dụng url.openstream ()
- Cách tiếp cận 1: Thư viện có tên Trình làm phim cung cấp cách đọc bất kỳ tệp nào bất kể bất kỳ tiện ích mở rộng nào. Cách để nối các dòng HTML vào trình tạo chuỗi như sau:
- Sử dụng trình filereader để đọc tệp từ thư mục nguồn và xa hơn nữabr.close().
- Nối mỗi dòng vào trình xây dựng chuỗi.
Implementation:
Khi không còn nội dung nào trong tài liệu HTML thì hãy đóng tệp mở bằng hàm br.close ().
In ra chuỗi.
Java
import java.io.*;
public class GFG {
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 8
public FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 1 FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 2 FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 3
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 5 FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 6
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));8BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));9
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));0BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));1 BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));2
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));4BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));1 BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));6
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }8
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }1 FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 8
import4import5
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7import7
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7import9
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7java.io.*;1
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7java.io.*;3
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4import7
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }4BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));1 while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }6
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7public0
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4import7
import7
import7
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7import0 import1import2import3
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4java.io.*;7 java.io.*;8Using the Url.openStream()
- Đầu ra: & nbsp;url.openStream()function that initiates the new TCPconnection to the Server that the URL provides it to.
- Cách tiếp cận 2: Sử dụng url.openstream ()
- Gọi hàm URL.openStream () khởi tạo TCPConnection mới đến máy chủ mà URL cung cấp cho nó.
- Bây giờ, HTTP nhận được yêu cầu được gửi đến kết nối sau khi máy chủ gửi lại phản hồi HTTP chứa thông tin vào đó.openStream()to fetch the information. The information is contained in the URL in the form of bytes if the connection is all OK (means is shows 200) then HTTP request to theURLTo fetch the content.
- Thông tin đó ở dạng byte sau đó thông tin đó được đọc bằng phương thức inputStreamReader () và openStream () trả lại dữ liệu cho chương trình. inputStreamReader()
- Đầu tiên, chúng tôi mở URL bằng TheopenStream () để tìm nạp thông tin. Thông tin được chứa trong URL dưới dạng byte nếu kết nối hoàn toàn ổn (có nghĩa là hiển thị 200) sau đó yêu cầu HTTP để tìm nạp nội dung.
Implementation:
Khi không còn nội dung nào trong tài liệu HTML thì hãy đóng tệp mở bằng hàm br.close ().
In ra chuỗi.
Java
import java.io.*;
Java
import java.io.*;
public class GFG {
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 8
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));0BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));1 BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));2
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }8
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));4BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));1 BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));6
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }1 FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 8
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }4BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));1 while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }6
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }1 FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 8
import4FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 07
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7import7
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7java.io.*;3
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4import7
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }4BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));1 while ((val = br.readLine()) != null) // condition { System.out.println(val); // execution if condition is true }6
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7public0
FileWriter fWriter = null; BufferedWriter writer = null; try { fWriter = new FileWriter("fileName.html"); writer = new BufferedWriter(fWriter); writer.write("<span>This iss your html content here</span>"); writer.newLine(); //this is not actually needed for html files - can make your code more readable though writer.close(); //make sure you close the writer object } catch (Exception e) { //catch any exceptions here } 4import7
import7
import7
BufferedReader br = new BufferedReader(new InputStreamReader(URL.openStream()));7import0 import1import2import3