Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String[] parts = response.split("`");
- String part1 = parts[0];
- //part1 contains file name....now send the file or file size
- File file= new File(part1);
- System.out.println("File exists: " + file.exists());
- System.out.println("File can be read: " + file.canRead());
- System.out.println("File file.canWrite(): " + file.canWrite());
- if ( file.exists() && file.canRead() )
- {
- // return the number of bytes in the file as a long int
- long file_size= file.length();
- System.out.println("File size is: " + file_size);
- if ( file_size > 0 )
- {
- System.out.println("432211");
- output.writeLong( file_size );
- System.out.println("File size sent.");
- }
- else
- {
- output.writeLong( 0L );
- }
- }
- else
- {
- output.writeLong( 0L );
- }
- FileInputStream file_input= new FileInputStream(file);
- System.out.println( "Transmitting file: " + part1);
- byte[] file_buffer= new byte[1500];
- int number_read;
- while( (number_read= file_input.read( file_buffer )) != -1 )
- output.write( file_buffer, 0, number_read );
- System.out.println("File " + part1 + " sent with " + number_read + " bytes read.");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement