Search the Community
Showing results for tags 'java'.
Found 27 results
-
Sveiki programmētāji. Taisu vienu projektiņu un esmu apstājies pie datu nolasīšanas no excel faila. meklēju googlē, bet katrs jaunais, ko atrodu, ir kompilcētāks par iepriekšējo un īsti triviālu (cik nu tas ir iespējams) neko nevaru atrast. Man ir jānolasa dati no excel faila, bet ne viss. Veidojas tabula ar, protams, nosaukumiem augšā. Viss kopā ir gads, iekļautas 2 sezonas - ziemas un vasaras. Tās sadalītas mēnešos. (tas pa kolonnām). rindas sadalītas pēc 4 citiem kritērijiem. Un man ir jāapstrādā pa kolonnām, pa rindām, pa sezonām un viss kopā. kā to lai izdara? apmēram? petiks ar linku uz LABU materiālu, klases (kas darbojās šajā sektorā) nosaukums utt. ļoti ceru, ka ir tādas lietas kā, piemēram, getCell(int, char); nu vai kkas tāds. Tnx!
- 6 atbildes
-
Tātad, man ir udevums, izmantojot internetu( kodus var meklēt arī internetā ) atrast un izpidīt sekojošu uzdevumu: Jāizveido čats, klients-servers programmu. Nepieciešams čatošanas rezultātus saglabāt failā/os (logošana) servera pusē. Programmu esmu atradis un pārbaudījis tās darbību, vienīgā problēma ir tāda, ka es nekādīgi nespēju izveidot operāciju, lai visu čatošanu programma saglabātu failā (os (logošana) servera pusē). Varbūt kāds varētu palīdzēt šajā sakarā? Kodi : Servera kods - package multithreadchatserver; import java.io.*; import java.net.*; public class MultiThreadChatServer{ static Socket clientSocket = null; static ServerSocket serverSocket = null; static clientThread t[] = new clientThread[10]; public static void main(String args[]) { int port_number=2222; if (args.length < 1) { System.out.println("Usage: java MultiThreadChatServer \n"+ "Now using port number="+port_number); } else { port_number=Integer.valueOf(args[0]).intValue(); } try { serverSocket = new ServerSocket(port_number); } catch (IOException e) {System.out.println(e);} while(true){ try { clientSocket = serverSocket.accept(); for(int i=0; i<=9; i++){ if(t[i]==null) { (t[i] = new clientThread(clientSocket,t)).start(); break; } } } catch (IOException e) { System.out.println(e);} } } } class clientThread extends Thread{ DataInputStream is = null; PrintStream os = null; Socket clientSocket = null; clientThread t[]; public clientThread(Socket clientSocket, clientThread[] t){ this.clientSocket=clientSocket; this.t=t; } public void run() { String line; String name; try{ is = new DataInputStream(clientSocket.getInputStream()); os = new PrintStream(clientSocket.getOutputStream()); os.println("Enter your name."); name = is.readLine(); os.println("Hello "+name+" to our chat room.\nTo leave enter /quit in a new line"); for(int i=0; i<=9; i++) if (t[i]!=null && t[i]!=this) t[i].os.println("*** A new user "+name+" entered the chat room !!! ***" ); while (true) { line = is.readLine(); if(line.startsWith("/quit")) break; for(int i=0; i<=9; i++) if (t[i]!=null) t[i].os.println("<"+name+"> "+line); } for(int i=0; i<=9; i++) if (t[i]!=null && t[i]!=this) t[i].os.println("*** The user "+name+" is leaving the chat room !!! ***" ); os.println("*** Bye "+name+" ***"); for(int i=0; i<=9; i++) if (t[i]==this) t[i]=null; is.close(); os.close(); clientSocket.close(); } catch(IOException e){}; } } Klienta kods: package multithreadchatclient; import java.io.*; import java.net.*; public class MultiThreadChatClient implements Runnable{ static Socket clientSocket = null; static PrintStream os = null; static DataInputStream is = null; static BufferedReader inputLine = null; static boolean closed = false; public static void main(String[] args) { int port_number=2222; String host="localhost"; if (args.length < 2) { System.out.println("Usage: java MultiThreadChatClient \n"+ "Now using host="+host+", port_number="+port_number); } else { host=args[0]; port_number=Integer.valueOf(args[1]).intValue(); } try { clientSocket = new Socket(host, port_number); inputLine = new BufferedReader(new InputStreamReader(System.in)); os = new PrintStream(clientSocket.getOutputStream()); is = new DataInputStream(clientSocket.getInputStream()); } catch (UnknownHostException e) { System.err.println("Don't know about host "+host); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to the host "+host); } if (clientSocket != null && os != null && is != null) { try { new Thread(new MultiThreadChatClient()).start(); while (!closed) { os.println(inputLine.readLine()); } os.close(); is.close(); clientSocket.close(); } catch (IOException e) { System.err.println("IOException: " + e); } } } public void run() { String responseLine; try{ while ((responseLine = is.readLine()) != null) { System.out.println(responseLine); if (responseLine.indexOf("*** Bye") != -1) break; } closed=true; } catch (IOException e) { System.err.println("IOException: " + e); } } }