java - Statement after while not executing in the client program -


i trying read file server , able successfully. however, @ client end statement after while loop not execute @ all. kindly me request. line asking client input not show @ all. please help

//client side code import java.io.*; import java.net.*; import java.util.stringtokenizer; import java.lang.*;  public class oss_client1 {     public static void main(string args[]) throws exception {          socket sock = new socket("127.0.0.1", 2222);         char n1;         int choice;          // reading file name keyboard. uses input stream         bufferedreader keyread = new bufferedreader(new inputstreamreader(                 system.in));         bufferedreader dis = new bufferedreader(                 new inputstreamreader(system.in));          // receiving contents server. uses input stream         inputstream istream = sock.getinputstream();         inputstream istream1 = sock.getinputstream();           // sending file name server. uses printwriter         outputstream ostream = sock.getoutputstream();         bufferedreader dread = new bufferedreader(                 new inputstreamreader(istream));         bufferedreader socketread = new bufferedreader(new inputstreamreader(                 istream1));           printwriter pwrite = new printwriter(ostream, true);         printwriter pwrite1 = new printwriter(ostream, true);          {             system.out.println("enter website name: ");             string u_input = keyread.readline();             pwrite.println(u_input);             string str;              while ((str = dread.readline()) != null) {                 // reading line-by-line                 system.out.println(str);             }               str = dread.readline();             system.out.println(str);             dread.close();              system.out                     .print("\nplease enter product code want buy: ");              string pcode = dis.readline();             pwrite1.println(pcode);             string pcode_res = socketread.readline();              system.out.print("\nback server " + pcode_res + "\n");             system.out.println("\ndo want continue(y/n)");             string n = dis.readline();             n1 = n.charat(0);          } while (n1 == 'y' || n1 == 'y');          pwrite.close();         socketread.close();         keyread.close();     }  } 

//server side code

import java.net.*; import java.util.*; import java.io.*;  public class oss_server1 {     static socket clientsocket = null;     static serversocket serversocket = null;     static clientthread t[] = new clientthread[10];      public static void main(string args[]) throws exception {          int port_number = 2222; // default port          if (args.length < 1) {             system.out.println("now using port number=" + port_number);         } else {             port_number = integer.valueof(args[0]).intvalue();         }          /* try open server socket on port port_number (default 2222) */         try {             serversocket = new serversocket(port_number);         } catch (ioexception e) {             system.out.println(e);         }          while (true) {             try {                 clientsocket = serversocket.accept();                 (int = 0; <= 9; i++) {                     if (t[i] == null) {                         (t[i] = new clientthread(clientsocket, t)).start();                         port_number++;                         break;                     } // end of if loop                 } // end looop             }// end of try loop             catch (ioexception e) {                 system.out.println(e);             }         } // end of while loop      } }  class clientthread extends thread {       datainputstream = null;     dataoutputstream dout = null;     socket clientsocket = null;     clientthread t[];      public clientthread(socket clientsocket, clientthread[] t) {         this.clientsocket = clientsocket;         this.t = t;     }      public void run() {         try {             system.out.println("welcome online shopping system");             string website = "www.us_oss.com";              // buffer stream reading choice client             inputstream istream = clientsocket.getinputstream();             inputstream istream1 = clientsocket.getinputstream();             bufferedreader webread = new bufferedreader(new inputstreamreader(istream));             bufferedreader pcoderead = new bufferedreader(new inputstreamreader(istream));               // buffer stream reading file contents             bufferedreader displayread = new bufferedreader(new filereader(                     "display_client.txt"));             bufferedreader prodread = new bufferedreader(new filereader(                     "product_list.txt"));              // keeping output stream ready send contents             outputstream ostream = clientsocket.getoutputstream();             printwriter pwrite = new printwriter(ostream, true);             string str, str1, pcode;             string fname = webread.readline();             if (fname.compareto(website) != 0) {                 pwrite.println("error 404: not found");             } else {                 while ((str = displayread.readline()) != null) // reading line-by-line file                  {                     pwrite.println(str);                 }                 displayread.close();                 str = "end of product list";                  pwrite.println(str);                 pcode = pcoderead.readline();                 system.out.print("\nreceived pcode is: " + pcode);                 pwrite.println(pcode);             }             // pwrite.close();         } // end of try block         catch (ioexception e) {             system.out.println(e);         }      } // end of run class }// end of client thread class  

bufferedreader when reading after eof issue ioexception

instead suggest use scanner read files code like...(in serverside)

scanner scnfile=new scanner(new file("display_client.txt")); //give absolute path if necessary  while(scnfile.hasnext()){  system.out.println(scnfile.nextline());  }  scnfile.close(); 

Comments