English 中文(简体)
用java语处理印地语
原标题:Handling Hindi language in java
  • 时间:2012-05-23 07:14:20
  •  标签:
  • java
  • hindi

我有一个链接“ http://bkwsu. org/ thoughtText?lang=hi ”, 我从中检索json 数据, 我从中提取了印地语文本, 然后又在 java 中提取了文本。 然后我试图将这个hindi 文本张贴到 fb 页面 。 现在的问题是当我将数据张贴到 fb 页面时, 它会显示一些胡言乱语 。 以下是我的代码 :

import java.util.*;
import java.io.*;
import com.restfb.*;
import java.net.*;
import com.restfb.json.*;
import com.restfb.types.*;
public class MurliPost
{
    public static void main(String args[])throws Exception{
        String temp1="",temp = "";
        URL u=new URL("http://bkwsu.org/thoughtText?lang=hi");
        HttpURLConnection uc=(HttpURLConnection) u.openConnection();
        uc.setDoOutput(true);
        uc.setDoInput(true);
        uc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.29 (KHTML, like Gecko) Chrome/12.0.733.0 Safari/534.29");
        uc.setRequestProperty("Connection","keep-alive");
        uc.setRequestProperty("Accept","text/html,application/xhtml+xml,application/xml");
        uc.setRequestProperty("Accept-Language","en-US,en;q=0.8");
        uc.setRequestProperty("Accept-Charset","ISO-8859-1,utf-8;q=0.7,*;q=0.3");
        uc.setRequestMethod("GET");
        uc.setInstanceFollowRedirects(false);
        BufferedReader br = new BufferedReader(new InputStreamReader(uc.getInputStream()));
        while ((temp=br.readLine())!=null){temp1+="
"+temp;}
        String murli=temp1.substring(temp1.indexOf(" text : ")+8,temp1.indexOf(" ,
 topic :"));
        murli=murli.replace("\r\n\r\n","

");
        murli=murli.replace("\r\n","

");
        murli=murli.replaceAll("[ 	]+", " ");
        Date date=new Date();
        murli=String.valueOf(date.getDate())+"/"+String.valueOf(date.getMonth()+1)+"/"+String.valueOf(1990+date.getYear())+"

"+murli;
        System.out.println(murli);
        DefaultFacebookClient facebookClient=new DefaultFacebookClient("your access token goes here");
        JsonObject j=facebookClient.fetchObject("me/accounts",JsonObject.class);
        JsonArray acc=j.getJsonArray("data");
        for(int i=0;i<acc.length();i++) 
            if(acc.getJsonObject(i).getString("name").equals("Brahma Kumaris")) {
                DefaultFacebookClient facebookClient1=new DefaultFacebookClient(acc.getJsonObject(i).getString("access_token"));
                String posturl=acc.getJsonObject(i).getString("id")+"/feed";
                FacebookType publishMessageResponse=facebookClient1.publish(posturl,FacebookType.class,Parameter.with("message",murli));
                System.out.println("success");
                break;
            }
    }
}

那么我该如何在java处理这个问题呢?

最佳回答

您应该指定当即时输入StreamReader 时的编码, 否则默认系统编码会应用到 Get 请求的输出上, 如果它与响应中返回的编码不匹配, 这会损坏字符 。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签