求各位大神的,java如何把一段字符串保持为html文件的java代码

求各位大神的,java如何把一段字符串保持为html文件的java代码,第1张

使用Java中的File类,url为文件的绝对地址,str为输入的字符串内容。代码如下图所示:String str="i love china!" File txt=new File("url") if(!txt.exists()){ txt.createNewFile() } byte bytes[]=new byte[512] bytes=str.getBytes() //新加的 int b=str.length() //改 FileOutputStream fos=new FileOutputStream(txt) fos.write(bytes,0,b) fos.close()

在html中点击保存网页的动作需要js来实现:

<script type="text/javascript">

//添加key-value 数据到 sessionStorage

sessionStorage.setItem("demokey", "http://blog.itjeek.com")

//通过key来获取value

var dt = sessionStorage.getItem("demokey")

alert(dt)

//清空所有的key-value数据。

//sessionStorage.clear()

alert(sessionStorage.length)

</script>

点击保存,就会d出对话框,选择路径即可。

可以通过Spire.Doc for Java进行转换。

首先需要安装Spire.Doc for Java。可在 Java 程序中添加 Spire.Doc for Java 文件作为依赖项。JAR 文件可以从此链接下载。 如果您使用 Maven,则可以将以下代码添加到项目的 pom.xml 文件中,从而轻松地在应用程序中导入 JAR 文件。

<repositories>

<repository>

<id>com.e-iceblue</id>

<name>e-iceblue</name>

<url>https://repo.e-iceblue.cn/repository/maven-public/</url>

</repository></repositories><dependencies>

<dependency>

<groupId>e-iceblue</groupId>

<artifactId>spire.doc</artifactId>

<version>5.2.3</version>

</dependency></dependencies>

Java代码如下:

mport com.spire.doc.*public class WordtoHtml {

public static void main(String[] args) {

//实例化Document类的对象

Document  doc = new Document()

//加载Word文档

doc.loadFromFile("inputfile.docx")

//保存为HTML格式

doc.saveToFile("ToHtml.html",FileFormat.Html)

doc.dispose()

}

}

希望对您有帮助。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zaji/7308710.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-04
下一篇2023-04-04

发表评论

登录后才能评论

评论列表(0条)

    保存