How to write UTF-8 encoded data into a file – Java

Here’s the Java example to demonstrate how to write UTF-8 encoded data into a text file – “c:\\temp\\test.txt”

P.S Symbol “??” is some “UTF-8″ data in Chinese and Japanese

package com.mkyong;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

public class test {
	public static void main(String[] args){

	  try {
		File fileDir = new File("c:\\temp\\test.txt");

		Writer out = new BufferedWriter(new OutputStreamWriter(
			new FileOutputStream(fileDir), "UTF8"));

		out.append("Website UTF-8").append("\r\n");
		out.append("?? UTF-8").append("\r\n");
		out.append("??????? UTF-8").append("\r\n");

		out.flush();
		out.close();

	    }
	   catch (UnsupportedEncodingException e)
	   {
		System.out.println(e.getMessage());
	   }
	   catch (IOException e)
	   {
		System.out.println(e.getMessage());
	    }
	   catch (Exception e)
	   {
		System.out.println(e.getMessage());
	   }
	}
}

  

时间: 2024-10-13 07:29:20

How to write UTF-8 encoded data into a file – Java的相关文章

NetSuite SuiteScript 2.0 export data to Excel file(xls)

In NetSuite SuiteScript, We usually do/implement export data to CSV, that's straight forward: Collect 'encoded' string to Array for column, join them with comma ',' to be a string. Collect each line's data same as column to push to the Array. Join al

Weka 3: Data Mining Software in Java

官方网站: Weka 3: Data Mining Software in Java   相关使用方法博客: WEKA使用教程(经典教程转载) Weka初步一.二.三.四 使用Weka进行数据挖掘 一个小时速度入门数据挖掘WEKA(一个完整的小例子)   百度文库: WEKA中文详细教程(全) WEKA 3-5-3 Experimenter 指南 数据挖掘工具(weka教程)

Import Data from *.xlsx file to DB Table through OAF page(转)

Use  Poi.jar Import Data from *.xlsx file to DB Table through OAF page Use Jxl.jar Import Data from Excel sheet to DB Table through OAF page

What is “passive data structure” in Android/Java?

From the Android developer web link: http://developer.android.com/reference/android/content/Intent.html, you can find that it says "It (Intent) is basically a passive data structure holding an abstract description of an action to be performed."

Sample: Write And Read data from HDFS with java API

HDFS: hadoop distributed file system 它抽象了整个集群的存储资源,可以存放大文件. 文件采用分块存储复制的设计.块的默认大小是64M. 流式数据访问,一次写入(现支持append),多次读取. 不适合的方面: 低延迟的数据访问 解决方案:HBASE 大量的小文件 解决方案:combinefileinputformat ,或直接把小文件合并成sequencefile存储到hdfs. HDFS的块 块是独立的存储单元.但是如果文件小于默认的块大小如64M,它不会占

Android App data write as file data with synchronous Demo

1 package com.android.utils; 2 3 import java.io.File; 4 import java.io.IOException; 5 import java.io.RandomAccessFile; 6 import java.util.Arrays; 7 8 import android.app.Activity; 9 import android.util.Log; 10 11 12 /** 13 * 在一些对数据实时性要求比较高的场合,如随时可能断电的

Convert Excel data to MDB file

所需组件: microsoft ado ext. 2.8 for ddl and security 或者更新的组件. 添加: using ADOX;using System.Runtime.InteropServices;using System.IO; 然后利用OleDbCommand组件,设置其2个链接,一个链接负责查找并打开excel数据源,另一个链接负责将数据源插入到MDB文件中. 操作页面: 后台源码: private void button1_Click(object sender,

[Python] Read and plot data from csv file

Install: pip install pandas pip install matplotlib # check out the doc from site import pandas as pd import matplotlib.pyplot as plt from numpy import mean def load_df(symbol): return pd.read_csv("data/{0}.csv".format(symbol)) def get_max_close(

使用Spring data Jpa 时遇到 java.lang.ClassNotFoundException: org.springframework.core.ReactiveTypeDescriptor

背景 原本项目是使用SSM+Maven进行开发,而后想同时使用Jpa(即mybatis和jpa混用),配置好相关文件后,使用Junit做测试时,出现以下错误. 主要: ERROR - Caught exception while allowing TestExecutionListener [org.springframewor[email protected]29774679] to prepare test instance [[email protected]]java.lang.Ille