piffy

Java Textfile (contacaratteri multiforme)

Jan 2nd, 2018
140
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.net.ServerSocket;
  3. import java.net.Socket;
  4.  
  5.  
  6. public class TextFile {
  7.     public static void main(String[] args) throws IOException {
  8.  
  9.         final int scelta = 0;
  10.  
  11.         int c;
  12.         int totali;
  13.         int spazi = 0;
  14.         ServerSocket ss = new ServerSocket(2000);
  15.         Socket socket = ss.accept();
  16.  
  17.         FileReader fileReader = new FileReader("loremipsum.txt");
  18.         InputStreamReader isr = new InputStreamReader(System.in);
  19.         InputStreamReader sisr = new InputStreamReader(socket.getInputStream());
  20.         BufferedReader in;
  21.  
  22.         switch (scelta) {
  23.             case 1: in = new BufferedReader(isr); break;
  24.             case 2: in = new BufferedReader(sisr);
  25.             default: in =  new BufferedReader(fileReader); break;
  26.         }
  27.  
  28.         for (totali=0; (c = in.read()) != -1; totali++)
  29.             if (Character.isWhitespace((char) c))
  30.                 spazi++;
  31.  
  32.         System.out.println(totali + " caratteri, " + spazi + " spazi");
  33.  
  34.         }
  35.  
  36.  
  37. }
RAW Paste Data