分类:java share 发布 2009.03.31 01:03:01Tag : java,php,Runtime,Properties,Properties,Enumeration commentComment:0
17
dig bury

关于对txt文件的读写java用起来真的是十分的麻烦,很多代码现在也不是很理解

import java.util.Properties;
import java.io.*;
public class PropertiesFile {
public static void main(String [] args){
 Properties settings = new Properties();
 try{
 settings.load(new FileInputStream("count.txt"));
 }catch(Exception e){
  settings.setProperty("count",String.valueOf(0));
 }
 int c = Integer.parseInt(settings.getProperty("count"))+1;
 System.out.print("这是第:" + c+"运行");
 settings.setProperty("count", new Integer(c).toString());
 try{
 settings.store(new FileOutputStream("count.txt"),"Program is used:");
 }catch(Exception e){
  e.printStackTrace();
 }
}
}

 

php对文件的读写

fopen   

fread

    fwrite

    fclose

关于调用windows中的进程,似乎php很难做到,也许是我不知道,java简单调用文本进程

import java.util.*;

public class lesson11 {
 public static void main(String[] args) {

  Properties sp = System.getProperties();
  Enumeration e = sp.propertyNames();
  while (e.hasMoreElements()) {
   String key = (String) e.nextElement();
   System.out.println(key + "=" + sp.getProperty(key));
  }
   Process p = null;
   try{
   p = Runtime.getRuntime (). exec ("notepad . exe  count . txt");
   Thread.sleep(5000);
   p.destroy();
   //System.exit(0);
   }catch(Exception ex){
    ex.printStackTrace();
   }
  
 }
}
 

我也来说2句,请不要发表违反法律的言论

姓名

Email(必填)

主页(不要加http://)