开发者

Java to C# code converter [duplicate]

开发者 https://www.devze.com 2023-01-01 17:20 出处:网络
This question already has answers here: Tool to convert java to c# code [closed] (4 answers) Closed 6 years ago.
This question already has answers here: Tool to convert java to c# code [closed] (4 answers) Closed 6 years ago.

Are there any converters available that converts Java code to C#?

I need to convert the below code into C#

String token = new String(""); 
URL url1 =new URL( "http", domain, Integer.valueOf(portnum), "/Workplace/setCredentials?op=getUserToken&userId="+username+"&password="+password +"&verify=true"); 
URLConnection conn1=url1.openConnection(); 
((HttpURLConnection)conn1).setRequestMethod("POST"); 
InputStream contentFileUrlStream = conn1.getInputStream(); 
BufferedReader br = new BufferedReader(new InputStreamReader(contentFileUrlStream)); 
token=br.readLine(); 

String encodedAPIToken = URLEncoder.encode(token); 
String doubleEncodedAPIToken ="ut=开发者_JAVA技巧" + encodedAPIToken;//.substring(0, encodedAPIToken.length()-1); 
//String doubleEncodedAPIToken ="ut=" + URLEncoder.encode(encodedAPIToken); 
//String userToken = "ut=" + URLEncoder.encode(token, "UTF-8"); //URLEncoder.encode(token); 
String vsId = "vsId=" + URLEncoder.encode(docId.substring(5, docId.length()), "UTF-8"); 
url="http://" + domain + ":" + portnum + "/Workplace/getContent?objectStoreName=RMROS&objectType=document&" + vsId + "&" +doubleEncodedAPIToken; 
String vsId = "vsId=" + URLEncoder.encode(docId.substring(5, docId.length()), "UTF-8"); 
url="http://" + domain + ":" + portnum + "/Workplace/getContent?objectStoreName=RMROS&objectType=document&" + vsId + "&" +doubleEncodedAPIToken; 

Thanks in advance


The below links might help:

  1. Microsoft Launches Java-to-C# Converter;
  2. Tangible Software Solutions inc..


The code is not very complicated, but if you don't have the time to translate it, you can use a tool like JLCA(Java Language Conversion Assistant 2.0).


You can try VaryCode Domain no longer exists and no valid snapshots in the Wayback Machine

But you used classes like URLEncoder, BufferedReader etc. that are hard to convert to C# without losing some Java-specific features. For this particular part of code it is insignificant but in prospect you can get some unpredicted behavior of the whole converted program.

0

精彩评论

暂无评论...
验证码 换一张
取 消