You must Sign In to post a response.
  • Category: General

    Convert VB.NET code to Java

    Private Sub UploadFile(ByVal filename As String)
    Try
    Dim strFile As String = System.IO.Path.GetFileName(filename)
    Dim fInfo As New FileInfo(filename)
    Dim numBytes As Long = fInfo.Length
    Dim dLen As Double = Convert.ToDouble(fInfo.Length / 1000000)
    If dLen < 4 Then
    Dim fStream As New FileStream(filename, FileMode.Open, FileAccess.Read)
    Dim br As New BinaryReader(fStream)
    Dim data As Byte() = br.ReadBytes(CInt(numBytes))
    br.Close()
    Dim sTmp As String = Me.objService.UploadFile(data, strFile)
    fStream.Close()
    fStream.Dispose()
    MessageBox.Show("File Upload Status: " & sTmp, "File Upload")
    Else
    MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size")
    End If
    Catch ex As Exception
    _objLog.WriteToErrorLog("Synchronization", "UploadFile", ex.Message, "")
    If MessageBox.Show(ex.Message, "Msg", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.OK Then
    Exit Sub
    End If
    End Try
    End Sub

    Thanks and regards
    kumar
  • #759089
    Hi Brite.

    Refer below code.


    import javax.swing.*;

    private void UploadFile(String filename)
    {
    try
    {
    String strFile = (new java.io.File(filename)).getName();
    java.io.File fInfo = new java.io.File(filename);
    long numBytes = fInfo.length();
    double dLen = (double)(fInfo.length() / 1000000);
    if (dLen < 4)
    {
    FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
    BinaryReader br = new BinaryReader(fStream);
    byte[] data = br.ReadBytes((int)numBytes);
    br.Close();
    String sTmp = this.objService.UploadFile(data, strFile);
    fStream.Close();
    fStream.Dispose();
    JOptionPane.showConfirmDialog(null, "File Upload Status: " + sTmp, "File Upload", JOptionPane.DEFAULT_OPTION);
    }
    else
    {
    JOptionPane.showConfirmDialog(null, "The file selected exceeds the size limit for uploads.", "File Size", JOptionPane.DEFAULT_OPTION);
    }
    }
    catch (RuntimeException ex)
    {
    _objLog.WriteToErrorLog("Synchronization", "UploadFile", ex.getMessage(), "");
    if (JOptionPane.showConfirmDialog(null, ex.getMessage(), "Msg", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE) == Windows.Forms.DialogResult.OK)
    {
    return;


    There are many on-line converters and off line converters as well. You can google it.
    Mark answer if you are satisfied.

    Regards

    Sridhar.
    DNS Member.
    "Hope for the best.. Prepare for the worst.."

    Sridhar Thota.
    Editor: DNS Forum.

  • #759090
    Hello Brite,

    Please do not expect from us like code conversion.

    You can convert your code online.

    Your Java code:

    import javax.swing.*;

    private void UploadFile(String filename)
    {
    try
    {
    String strFile = (new java.io.File(filename)).getName();
    java.io.File fInfo = new java.io.File(filename);
    long numBytes = fInfo.length();
    double dLen = (double)(fInfo.length() / 1000000);
    if (dLen < 4)
    {
    FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
    BinaryReader br = new BinaryReader(fStream);
    //C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
    //ORIGINAL LINE: byte[] data = br.ReadBytes(Convert.ToInt32(numBytes));
    byte[] data = br.ReadBytes((int)numBytes);
    br.Close();
    String sTmp = this.objService.UploadFile(data, strFile);
    fStream.Close();
    fStream.Dispose();
    JOptionPane.showConfirmDialog(null, "File Upload Status: " + sTmp, "File Upload", JOptionPane.DEFAULT_OPTION);
    }
    else
    {
    JOptionPane.showConfirmDialog(null, "The file selected exceeds the size limit for uploads.", "File Size", JOptionPane.DEFAULT_OPTION);
    }
    }
    catch (RuntimeException ex)
    {
    _objLog.WriteToErrorLog("Synchronization", "UploadFile", ex.getMessage(), "");
    if (JOptionPane.showConfirmDialog(null, ex.getMessage(), "Msg", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE) == Windows.Forms.DialogResult.OK)
    {
    return;
    }
    }
    }

    You can convert your code from below link:
    http://www.tangiblesoftwaresolutions.com/Product_Details/Products.html

    Hope this will help you.
    Mark the answer if it helped you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


  • Sign In to post your comments