sabing

Rastreador encomenda

1 mensagem neste tópico

então eu estou com dificuldade de traduzir essa classe em java 

import java.io.*;
import java.net.*;
public class GravaXML {
	public static void main(String[] args) {
		SaveXML("C:/teste.xml");
	}
	public static void SaveXML(String mfile){
		try {
			File fileXML = new File(mfile);
			String xmlin = MontaBusca();
			URL url = new URL("http://websro.correios.com.br/sro_bin/sroii_xml.eventos ");
			URLConnection connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setUseCaches(false);
			connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
			connection.setAllowUserInteraction(false);
			PrintStream outStream = new PrintStream(connection.getOutputStream());
			outStream.println("usuario=ECT&senha=SRO&tipo=L&resultado=U&objetos=" + xmlin);
			outStream.close();
			DataInputStream inStream = new DataInputStream(connection.getInputStream());
			String inputLine;
			FileWriter f = new FileWriter(fileXML);
			while ((inputLine = inStream.readLine()) != null) {
				f.write(inputLine);
			}
			f.close();
			inStream.close();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	private static String MontaBusca(){
		String Objetos = "PH082984697BR";
		return Objetos;
	}
}

o Que fiz até agora pois esta dando erro

essas linhas

  Dim url As URL = New URL("http://websro.correios.com.br/sro_bin/sroii_xml.eventos ")
  Dim connection As URLConnection = url.openConnection

   Dim outStream As PrintStream = New PrintStream(connection.getOutputStream)

   Dim inStream As DataInputStream = New DataInputStream(connection.getInputStream)

   Dim f As FileWriter = FileWriter(fileXML)

Public Sub Localizar(ByRef MeuArquivo As String)
        Try
            Dim fileXML As FileStream = File.Create(MeuArquivo)
            Dim xmlin As String = ""
            Dim url As URL = New URL("http://websro.correios.com.br/sro_bin/sroii_xml.eventos ")
            Dim connection As URLConnection = url.openConnection
            connection.setDoOutput(True)
            connection.setUseCaches(False)
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
            connection.setAllowUserInteraction(False)
            Dim outStream As PrintStream = New PrintStream(connection.getOutputStream)
            outStream.println(("usuario=ECT&senha=SRO&tipo=L&resultado=U&objetos=" + xmlin))
            outStream.close()
            Dim inStream As DataInputStream = New DataInputStream(connection.getInputStream)
            Dim inputLine As String
            Dim f As FileWriter = New FileWriter(fileXML)

            While (Not (inStream.readLine) Is Nothing)
                f.write(inputLine)

            End While

            f.close()
            inStream.close()
        Catch e As Exception
            MsgBox(e.Message)
        End Try
    End Sub

 

0

Partilhar esta mensagem


Link para a mensagem
Partilhar noutros sites

Crie uma conta ou ligue-se para comentar

Só membros podem comentar

Criar nova conta

Registe para ter uma conta na nossa comunidade. É fácil!


Registar nova conta

Entra

Já tem conta? Inicie sessão aqui.


Entrar Agora