我想将文件从一个包复制到另一个包.
我尝试了Files.copy方法,但它用复制的文件替换了我的文件夹.
public static void main(String[] args) throws IOException {
InputStream in = CopyFileToDirectoryTest.class.getClassLoader()
.getResourceAsStream("com/stackoverflow/main/Movie.class");
Path path = Paths.get("D://folder");
long copy = Files.copy(in, path,StandardCopyOption.REPLACE_EXISTING);
System.out.println(copy);
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为它删除文件夹并创建文件夹名称的文件.
有没有办法在Java 8或我应该使用apache.commons.io?
可以说我有这个网站链接:http://checkip.amazonaws.com/ .我已经制作了一个java程序(实际程序,而不是网页),它读取了这个网页的内容(例如"25.25.25.25")并将其显示在jLabel(使用Netbeans IDE 1.7.3)中并且它可以工作.
现在我如何阅读同一网页的内容(例如"25.25.25.25")并将其作为普通文本显示在网页上(最终网页必须是.html而不是.php或者什么)?
我不介意任何脚本是html或javascript或任何东西,我只是需要它工作,以便当网页打开时,它可以读取如下内容:
"你的IP:25.25.25.25"
优选地读取的内容http://checkip.amazonaws.com/成
<script>var ip = needCodeHere</script>
Run Code Online (Sandbox Code Playgroud)
如果我可以将IP转换为var或将该网页的内容读入var我很高兴,但其他代码很高兴,只要它有效.
请帮助:(一直盯着谷歌几天,无法找到解决方案)
我希望能够将字符串中的\ r \ n字符转换为新行
示例John现在正在等待。\ r \ n我们能告诉您有关他的情况吗?\ r \ n他是一个伟大的人
转换成
约翰现在在等。
我们能谈谈他吗。
他是一个伟大的人
尝试了这个但无济于事
nl2br(text: string) {
return text.replace(new RegExp('\r?\n','g'), '<br />');
}
Run Code Online (Sandbox Code Playgroud) How can it be done? I tried to write my html file like this:
<html>
<head>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
but it don't think that it forced html 5, in fact it didnt even work