「java更新文件」jar 更新文件

博主:adminadmin 2022-12-29 18:57:07 1106

今天给各位分享java更新文件的知识,其中也会对jar 更新文件进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java如何实现两台计算机之间文件夹同步更新

实现两台电脑同步文件夹的方法:

1、在登录完成之后,客户端会自动弹出配置向导。

2、选择目标文件夹之后,客户端会自动在该文件夹下面生成名为“”的同步文件夹。

即可实现成功。

java更新properties文件怎么刷新

首先你要明白一点,你更新后的文件不是你src下的,而是你生成的项目class 下的。 因此,如果你在程序中更新成功了,应该打开项目文件夹中找到class文件夹中的那个properties。当然了,如果我上面说的意思你是明白的话,可以参考一下其他网友做法。

import java.io.File; 

import java.io.FileInputStream; 

import java.io.FileOutputStream; 

import java.io.InputStream; 

import java.util.Properties; 

public class Test2 { 

   

public static void main(String[] args)  { 

try{ 

Properties prop = new Properties();// 属性集合对象 

java.net.URL  url = Test2.class.getResource("allen.properties");  

            

             File file = new File(url.toURI());  

           

           InputStream   fis = new FileInputStream(file);  

            

prop.load(fis);// 将属性文件流装载到Properties对象中 

fis.close();// 关闭流 

// 获取属性值,txnLogId已在文件中定义 

String txnLogId=prop.getProperty("txnLogId"); 

System.out.println("读取txnLogId属性的值:"+txnLogId); 

txnLogId=String.valueOf(Integer.parseInt(txnLogId)+1); 

prop.setProperty("txnLogId", txnLogId);// 修改sitename的属性值  

prop.setProperty("age", "25");//添加值 

// 文件输出流 

FileOutputStream fos = new FileOutputStream(file); 

// 将Properties集合保存到流中 

prop.store(fos, "update txnLogId value"); 

fos.close();// 关闭流 

}catch(Exception e){ 

e.printStackTrace(); 

}

java exe 怎么更新jar包

jar 应用 先打开命令提示符(win2000或在运行筐里执行cmd命令,win98为DOS提示符),输入jar -help,然后回车(如果你盘上已经有了jdk1.1或以上版本),看到什么:

用法:jar {ctxu}[vfm0Mi] [jar-文件] [manifest-文件] [-C 目录] 文件名 ...

选项:

-c 创建新的存档

-t 列出存档内容的列表

-x 展开存档中的命名的(或所有的〕文件

-u 更新已存在的存档

-v 生成详细输出到标准输出上

-f 指定存档文件名

-m 包含来自标明文件的标明信息

-0 只存储方式;未用ZIP压缩格式

-M 不产生所有项的清单(manifest〕文件

-i 为指定的jar文件产生索引信息

-C 改变到指定的目录,并且包含下列文件:

如果一个文件名是一个目录,它将被递归处理。

清单(manifest〕文件名和存档文件名都需要被指定,按'm' 和 'f'标志指定的相同顺序.

示例1:将两个class文件存档到一个名为 'classes.jar' 的存档文件中:

jar cvf classes.jar Foo.class Bar.class

示例2:用一个存在的清单(manifest)文件 'mymanifest' 将 foo/ 目录下的所有文件存档到一个名为 'classes.jar' 的存档文件中:

jar cvfm classes.jar mymanifest -C foo/ .

来个小例子试试看:

我们只有一个HelloWorld,如下:

public class HelloWorld{

public static void main(String[] args){

System.out.println("Hi, Hello World!");

}

}

我将这个java文件存到C盘跟目录下,ok,接下来,

在先前打开的命令提示符下(跳转到C盘提示符下),我们输入javac HelloWorld.java,然后继续输入:jar cvf hello.jar HelloWorld.class,回车后去你的C盘看看,多了什么,没错 hello.jar 。

基本的步骤我们现在都知道了,你可以自己去尝试一下随着jar后面的参数的不同,结果有什么变化。

紧接着我们看看如何运行我们的jar包。

在进入正题之前,你要先打开我们刚刚做好的jar包看看,多了什么呢,META-INF目录?再看看里面是什么,还有一个MANIFEST.MF文件是不是?用文本编辑器(我这里是UltraEdit)打开它看看:

Manifest-Version: 1.0

Created-By: 1.4.2 (Sun Microsystems Inc.)

就是这样。这里我们对它进行修改,加一句:Main-Class: HelloWorld (在第三行)。这个就是我们之前写的那个类,也就是我们的入口类。也即,

Manifest-Version: 1.0

Created-By: 1.4.2 (Sun Microsystems Inc.)

Main-Class: HelloWorld

接下来,我们在命令提示符里执行:

jar umf MANIFEST.MF app.jar

这样我们使用了我们自己的MANIFEST.MF文件对原来默认的进行了更新。你不妨可以再进去看看是不是添上了Main-Class: HelloWorld这一句。

Ok,这个最后的一步了,来验证我们做的一切,在命令提示符中输入:

java -jar hello.jar(执行)

出现了什么,――Hi, Hello World!

我们再来看看jar文件在tomcat中发布,注意:在tomcat中我们就不能再用jar这种格式,而改war格式,它是专门用于web应用的,其实整个过程下来基本上和jar是类似的:

先准备我们要打包的资源。

找到存放tomcat的webapps目录,进到其中,新建一个文件夹,这里命名为hello,再进去新建WEB-INF文件夹,再进去新建 classes文件夹,此时我们也将我们唯一的servlet,HelloWorld.java放到这里,在与classes目录同级下建立一文件 web.xml。Ok,目前我们初步建立了一个简单的web应用。

在命令提示符下进到先前创制的hello目录下,执行 jar cvf hello.war * ,我们便得到hello.war。将它拷贝至webapps目录下,ok,来看最后一步,打开tomcat的目录conf中的server.xml,加入:

reloadable="true"/

大功告成!运行它,启动tomcat,后在浏览器中输入,有了吗?

############

jar基本操作:

############

1. 创建jar文件

jar cf jar-file input-file(s)

c---want to Create a JAR file.

f---want the output to go to a file rather than to stdout.

eg: 1)jar cf myjar.jar query_maintain_insert.htm

2)jar cvf myjar.jar query_maintain_insert.htm

v---Produces verbose(详细的) output.

3)jar cvf myjar.jar query_maintain_insert.htm mydirectory

4)jar cv0f myjar.jar query_maintain_insert.htm mydirectory

0---don't want the JAR file to be compressed.

5)jar cmf MANIFEST.MF myjar.jar yahh.txt

m---Used to include manifest information from an existing manifest file.

6)jar cMf MANIFEST.MF myjar.jar yahh.txt

M---the default manifest file should not be produced.

7)jar cvf myjar.jar *

*---create all contents in current directory.

2. 察看jar文件

jar tf jar-file

t---want to view the Table of contents of the JAR file.

eg: 1)jar vft yahh.jar

v---Produces verbose(详细的) output.

3. 提取jar文件

jar xf jar-file [archived-file(s)]

x---want to extract files from the JAR archive.

eg: 1)jar xf yahh.jar yahh.txt(仅提取文件yahh.txt)

2)jar xf yahh.jar alex/yahhalex.txt(仅提取目录alex下的文件yahhalex.txt)

3)jar xf yahh.jar(提取该jar包中的所有文件或目录)

4. 修改Manifest文件

jar cmf manifest-addition jar-file input-file(s)

m---Used to include manifest information from an existing manifest file.

5. 更新jar文件

jar uf jar-file input-file(s)

u---want to update an existing JAR file.

--生成exe:--

第一种:在jbuilder中:

首先你要保证Run菜单--Run Project能顺利运行

然后Wizards菜单--Native Executable Builder

选中Compress the contents of the archive(产生jar文件的话)

Next--Next--选中Always include all classes and resources再Next--Next--Next

选中Windows GUI"exe"(产生EXE文件的话)--Finish

再在项目的文件列表中的Native Executable右击--Make就可以了

第二种:在cmd 下生成jar文件

abc.txt内容如下:

Manifest-Version: 1.0

Main-Class: main-class-name(回车)

在cmd下:

javac *.java

jar cvfm abc.jar abc.txt *.class

如何在java里面更新xml文件的信息

你要怎么更新?

一种是读取文件内容,利用dom4j解析,更新指定节点的值然后转成String;

一种是读取文件内容,你自己利用字符串解析xml内容并更新值,

最后写到文件覆盖。

java更新文件的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于jar 更新文件、java更新文件的信息别忘了在本站进行查找喔。