java 字符串编码格式转换

File txtFile = new File(filePath);
			FileInputStream fis= null;
	        fis=new FileInputStream(txtFile );
	        //读取的编码格式
	        BufferedReader br=new BufferedReader(new InputStreamReader(fis,"utf-8"));
	        String line = "";
	        StringBuffer jsonStr = new StringBuffer();
	        while((line = br.readLine()) != null){
	        	jsonStr.append(line);
	        }
	        String userInfo = jsonStr.toString();
	        //将字符串转为gbk格式的byte数组
			byte[] byteBuffer = userInfo.getBytes("gbk");
			//byte数组转字符串
			System.out.println(new String(byteBuffer,"gbk"));

你可能感兴趣的:(java 字符串编码格式转换)