0
將多個文件上傳到服務器。下面是客戶機代碼:將多個文件上傳到服務器
void SendFile() throws Exception
{
String path;
System.out.print("Enter File Path :");
path=br.readLine();
File f=new File(path);
File files[]=f.listFiles();
String fileName;
for(File file:files)
{
if(file.isFile())
{
fileName=file.getName();
dout.writeUTF(fileName);
System.out.println("Sending File ..."+fileName);
FileInputStream fin=new FileInputStream(f);
int ch;
do
{
ch=fin.read();
dout.writeUTF(String.valueOf(ch));
}
while(ch!=-1);
fin.close();
System.out.println(din.readUTF());
}
}
}
但發送單個文件後的程序產生錯誤:
Exception in thread "main" java.io.FileNotFoundException: /home/bdi-user/Desktop/files (Is a directory)
unix區分大小寫..請問您可以檢查文件夾名稱...無論是'files'還是'Files' – Shashi