userdata.java

来自「JAVA写的一个机器人程序」· Java 代码 · 共 35 行

JAVA
35
字号
package rebot;

import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class userdata {
    public static void userdata(String phrase, String dirname, String filename) {
        File dir = new File(dirname);
        File aFile = new File(dir, filename);
        FileOutputStream outputFile = null;
        try {
            outputFile = new FileOutputStream(aFile, true);
        } catch (FileNotFoundException e) {
            e.printStackTrace(System.err);
        }
        FileChannel outChannel = outputFile.getChannel();
        ByteBuffer buf = ByteBuffer.allocate(phrase.length() * 2);
        buf.clear();
        for (char ch : phrase.toCharArray()) {
            buf.putChar(ch);

        }
        buf.flip();
        buf.clear();
        try {
            outChannel.write(buf);
            outputFile.close();
            buf.clear();
        } catch (IOException e) {
            e.printStackTrace(System.err);
        }
    }
}

⌨️ 快捷键说明

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