logout.java

来自「SSO客户端」· Java 代码 · 共 58 行

JAVA
58
字号
/*
 * Logout.java
 *
 * Created on 2006年1月23日, 下午5:49
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package desktopsso;

import java.io.*;
import java.util.*;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
/**
 *
 * @author wangyu
 */
public class Logout {
    private static String cookiefilepath = "C:\\Documents and Settings\\yw137672\\Application Data\\Mozilla\\Profiles\\default\\hog6z1ji.slt\\cookies.txt";
    private static String cookiesign = "wangyu";
    private static final int BSIZE = 50*1024;
    private static final int cookieValueSize = 19;
    
   
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception{
       System.out.println("Logging out all applications....");
       int offset =foundCookie();
       if (offset >0) updateCookie(offset);
       System.out.println("ByeBye");
    }
    
    private static int foundCookie() throws IOException{
        FileChannel fr = new FileInputStream(cookiefilepath).getChannel();
        ByteBuffer buff = ByteBuffer.allocate(BSIZE);
        fr.read(buff);
        buff.flip();
        String allfile = new String(buff.array());
        int offset = allfile.indexOf(cookiesign);
        return offset;
    }
    
    private static void updateCookie(int offset)  throws IOException{
        
      
            FileChannel fc = new RandomAccessFile(cookiefilepath, "rw").getChannel();
            fc.position(offset);
            fc.write(ByteBuffer.wrap("wangyu11111".getBytes()));
            fc.close();
      
    }
}

⌨️ 快捷键说明

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