안녕하세요 DataInputStream.
의 readLong()
메서드로 문제가 있습니다. DataOutputStream.writeLong()
을 통해 값을 입력하면 올바른 값이지만 전송 될 때 더 커야합니다. 프로그램이DataInputStream readLong()이 잘못된 값을 얻음
이 클라이언트
socket = new Socket(ipAddress, Port);
bos = new BufferedOutputStream(socket.getOutputStream());
dos = new DataOutputStream(bos);
File f = new File("C:/Users/lukeLaptop/Downloads/RemoveWAT22.zip");
long length = f.length();
dos.writeLong(length);
String name = f.getName();
dos.writeUTF(name);
FileInputStream fis = new FileInputStream(f);
bis = new BufferedInputStream(fis);
int theByte = 0;
while ((theByte = bis.read()) != -1) {
bos.write(theByte);
}
bis.close();
dos.close();
서버 측
ServerSocket server = new ServerSocket(8080);
while (true) {
socket = server.accept();
System.out.println("Got a client !");
bis = new BufferedInputStream(socket.getInputStream());
dis = new DataInputStream(bis);
int filesCount = dis.readInt();
long fileLength = dis.readLong();
//String fileName = dis.readUTF();
File f = new File("C:/test/here/test.zip");
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(fos);
for (int j = 0; j < fileLength; j++) {
bos.write(bis.read());
}
bos.close();
dis.close();
이다 동결하지 않도록 내가 실행 가능한 한 Statment의 코드를 모두 가지고있을
EDIT
코드가 도움이된다면 소켓에 익숙하지 않고 약간 혼란스러워지고 있습니다. writeLong을 사용하여 파일의 길이를 보내고 싶습니다. 메서드를 사용하여 writeUTF 및 writeUTF 함께 이름을 보내지 만 무슨 일이 일어나고 어떻게 수정 해야할지 모르겠다.
코드에 GetLong()이 없습니다 ... – Rainbolt
오직 readlong 만 있고 항상 잘못된 값을 얻습니다. –
DataOutputStream에는 getLong() 또는 readLong() 메소드가 없습니다. 제목을 수정하십시오. – EJP