jadmodifier.java

来自「用Java写的彩信的程序。包括wsp/mime/mms几部分。」· Java 代码 · 共 75 行

JAVA
75
字号
/* 
 * JVending - J2ME MMS Client
 *
 * Distributed under Apache style software license included with the source code.
 */

package org.jvending.build.task;

import java.net.URL;
import java.net.MalformedURLException;

import java.io.FileInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import java.util.Properties;

import java.util.Enumeration;


/**
 * @author Shane Isbell
 * @version 1.0.0a
 * @created 04/03/27
 */

//A class that changes the size value in the JAD file, so I don't have to change it manually when using ANT.
public class JadModifier {

    private String jarUrl;

    private String jadUrl;

    public JadModifier(String jarUrl, String jadUrl) {
        this.jarUrl = jarUrl;
        this.jadUrl = jadUrl;
    }

    public void updateJarSize() {
        try {
            File file = new File(jarUrl);
            long jarLength = file.length();
            System.out.println("Jar Length:" + jarLength);
            FileInputStream fis = new FileInputStream(jadUrl);
            Properties prop = new Properties();
            prop.load(fis);
            prop.setProperty("MIDlet-Jar-Size", String.valueOf(jarLength));
            fis.close();
            FileOutputStream fos = new FileOutputStream(jadUrl);
            Enumeration enum = prop.propertyNames();
            String key = null;
            String value = null;

            while(enum.hasMoreElements()) {
                key = (String) enum.nextElement();
                value = (String) prop.getProperty(key);
                fos.write((key + ": " + value + "\r\n").getBytes());
            }
            fos.close();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String baseDir = "c:\\work_space2\\mms";
        String jadUrl = baseDir + "\\mms\\resources\\mms.jad";
        String jarUrl = baseDir + "\\mms\\resources\\mms.jar";

        JadModifier jm = new JadModifier(jarUrl, jadUrl);
        jm.updateJarSize();
    }
    
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?