未找到异常线程类

未找到异常线程类

本文介绍了在命令提示符下运行jar文件时显示“未找到异常线程类”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务器端程序





server side program


import java.net.*; 
import java.io.*; 
import java.util.Scanner;
public class Server 
{ 
    public static void main (String [] args ) throws IOException 
    { 
    int filesize=1022386; 
    int bytesRead; int currentTot = 0; 
      try
    {  
    ServerSocket serverSocket = new ServerSocket(9999); 
    Socket socket = serverSocket.accept(); 
    System.out.println("Accepted connection : " + socket);
    BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));    
    String temp=br.readLine();
    System.out.println("The mesage from client is::"+temp);
    PrintStream  pr=new PrintStream(socket.getOutputStream()); 
                String  str = "acknowledgement from server";
                pr.println(str);
    Scanner scanner = new Scanner(System.in);  
    String path_save = scanner.nextLine();
             
    byte [] bytearray = new byte [filesize]; 
    InputStream is = socket.getInputStream(); 
    FileOutputStream fos = new FileOutputStream(path_save); 
    BufferedOutputStream bos = new BufferedOutputStream(fos); 
    bytesRead = is.read(bytearray,0,bytearray.length); 
    currentTot = bytesRead; 
    
    
    
    do 
    { 
        bytesRead = is.read(bytearray, currentTot, (bytearray.length-currentTot)); 
        if(bytesRead >= 0) 
        currentTot += bytesRead; 
    } 
            while(bytesRead > -1); bos.write(bytearray, 0 , currentTot); 
            bos.flush(); bos.close(); socket.close();
    }
    catch(Exception ex)
        
    {
        System.err.println(ex.getClass().getName()+":"+ex.getMessage());
        System.exit(0);
        
    }
    }
}





客户端计划





client side program

import java.net.*; 
import java.io.*; 
import java.util.Scanner;
public class client 
{ 
    public static void main (String [] args ) throws IOException 
    { 
    int filesize=1022386; 
    int bytesRead; 
    int currentTot = 0; 
    try
    {
    Socket socket = new Socket("10.176.24.63",9999);
    Scanner scanner = new Scanner(System.in);  
    String path = scanner.nextLine();
    File transferFile = new File (path); 
                
        byte [] bytearray = new byte [(int)transferFile.length()]; 
        FileInputStream fin = new FileInputStream(transferFile); 
        BufferedInputStream bin = new BufferedInputStream(fin); 
        bin.read(bytearray,0,bytearray.length); 
        OutputStream os = socket.getOutputStream(); 
        PrintStream  pr=new PrintStream(socket.getOutputStream()); 
    
                    System.out.println("Enter the file name,type,path");
                    BufferedReader  br=new  BufferedReader(new InputStreamReader(System.in));  
                    String temp = br.readLine();
                    pr.println(temp);	
                    BufferedReader  ed=new  BufferedReader(new InputStreamReader(socket.getInputStream())); 
                    String  st = ed.readLine();
                    System.out.println(st);
        System.out.println("Sending Files..."); 
        os.write(bytearray,0,bytearray.length); 
        os.flush();
        socket.close(); 
        System.out.println("File transfer complete");
    }
        catch(Exception ex)
        {
            System.err.println(ex.getClass().getName()+":"+ex.getMessage());
            System.exit(0);
        }

    }
}

推荐答案


这篇关于在命令提示符下运行jar文件时显示“未找到异常线程类”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 00:51