App下載
首頁javatext_fileJava I/O - 如何寫UTF-8編碼數(shù)據(jù)

Java I/O - 如何寫UTF-8編碼數(shù)據(jù)

我們想知道如何寫UTF-8編碼數(shù)據(jù)。
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class Main {
  public static void main(String[] argv) throws Exception {

    Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("outfilename"),
        "UTF8"));
    out.write("asdf");
    out.close();
  }
}