JAVA向EXE文件尾追加配置信息,用于解决局版客户端的程序IP配置问题

package com.demo.blog;

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

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;

/**
 * BlogController
 * 所有 sql 与业务逻辑写在 Model 或 Service 中,不要写在 Controller 中,养成好习惯,有利于大型项目的开发与维护
 */
@Before(BlogInterceptor.class)
public class BlogController extends Controller {
    public void index() {
        File a = new File("c:/notepad.exe");
         try
            {
                String content = "10.10.6.6";            
                FileOutputStream fout=new FileOutputStream(a,true);
                DataOutputStream dout=new DataOutputStream(fout);
                dout.write(content.getBytes("UTF-8"));
                dout.writeInt(swapInteger(content.getBytes("UTF-8").length));
                dout.close();
                dout.flush();
            } catch (IOException e)
            {
                e.printStackTrace();
            }
        renderFile(a);
    }
     public static int swapInteger(int value) {
        
            return
                ((value & 0xFF000000) >> 24)
                | ((value & 0x00FF0000) >> 8)
                | ((value & 0x0000FF00) << 8)
                | ((value & 0x000000FF) << 24)
                ;           
        }
    public void add() {
    }
    
    @Before(BlogValidator.class)
    public void save() {
        getModel(Blog.class).save();
        redirect("/blog");
    }
    
    public void edit() {
        setAttr("blog", Blog.me.findById(getParaToInt()));
    }
    
    @Before(BlogValidator.class)
    public void update() {
        getModel(Blog.class).update();
        redirect("/blog");
    }
    
    public void delete() {
        Blog.me.deleteById(getParaToInt());
        redirect("/blog");
    }
}


参考链接:http://www.codeforge.cn/read/23518/EndianUtils.java__html

原文地址:https://www.cnblogs.com/littlehb/p/4825133.html