Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.ServerSocket;
- import java.net.Socket;
- public class TextFile {
- public static void main(String[] args) throws IOException {
- final int scelta = 0;
- int c;
- int totali;
- int spazi = 0;
- ServerSocket ss = new ServerSocket(2000);
- Socket socket = ss.accept();
- FileReader fileReader = new FileReader("loremipsum.txt");
- InputStreamReader isr = new InputStreamReader(System.in);
- InputStreamReader sisr = new InputStreamReader(socket.getInputStream());
- BufferedReader in;
- switch (scelta) {
- case 1: in = new BufferedReader(isr); break;
- case 2: in = new BufferedReader(sisr);
- default: in = new BufferedReader(fileReader); break;
- }
- for (totali=0; (c = in.read()) != -1; totali++)
- if (Character.isWhitespace((char) c))
- spazi++;
- System.out.println(totali + " caratteri, " + spazi + " spazi");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement