[英]How do i make an html document with html in it with java code
I want to write a java program that asks the user for information like name, age , etc. Then take that information and make an HTML document on my computer with the information in it. 我想编写一个Java程序,向用户询问姓名,年龄等信息。然后获取该信息,并在计算机上制作包含该信息的HTML文档。 I don't know where to start with making it a web page.
我不知道从哪里开始制作网页。 Here is my code so far:
到目前为止,这是我的代码:
import javax.swing.JOptionPane;
public class WritesHTML{
public static void main(String[] args){
String firstName = JOptionPane.showInputDialog("Enter first name:");
String lastName = JOptionPane.showInputDialog("Enter last name:");
String age = JOptionPane.showInputDialog("Enter age:");
String occupation = JOptionPane.showInputDialog("occupation:");
int numAge = Integer.parseInt(age);
}
}
HTML document contains simple text, it's only difference from a standard text file is in the .html
extension. HTML文档包含简单的文本,它与标准文本文件的唯一区别是
.html
扩展名。 What you need to do is piece the information about the user together as a text, either String
, StringBuffer
, or anything you can output into a file. 您需要做的是将有关用户的信息拼为文本,包括
String
, StringBuffer
或您可以输出到文件中的任何内容。 The text forms the HTML source code of your new page. 文本构成新页面的HTML源代码。 Then you need to create a new
File
object and dump the text into the file using a FileStream
. 然后,您需要创建一个新的
File
对象,并使用FileStream
将文本转储到文件中。 After you close the stream, the text will be added into your HTML file and that's your document. 关闭流后,文本将添加到HTML文件中,这就是您的文档。
I suggest you have a look at some tutorials about files and file streams for more info about how to piece this together, as it is too much to cover in detail in a single post. 我建议您看一些有关文件和文件流的教程,以获取有关如何将它们组合在一起的更多信息,因为太多内容无法在一篇文章中详细介绍。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.