I am trying to write a simple tcp client / server application that copies a file. I want the server to list the files that the client can copy. My code is still like this:
import java.io.*;
public class GetFileList
{
public static void main(String args[]) throws IOException{
File file = new File(".");
File[] files = file.listFiles();
System.out.println("Current dir : " + file.getCanonicalPath());
for (int fileInList = 0; fileInList < files.length; fileInList++)
{
System.out.println(files[fileInList].toString());
}
}
}
Conclusion:
Current dir : C:\Users\XXXXX\Documents\NetBeansProjects\Test
.\build
.\build.xml
.\manifest.mf
.\nbproject
.\src
.\UsersXXXXXDocumentsNetBeansProjectsTestsrcfile2.txt
My problem is that it gives me the parent directory instead of the current directory. My GetFileList.java is in C:\Users\XXXXX\Documents\NetBeansProjects\Test\src, but it shows. C:\Users\Alick\Documents\NetBeansProjects\TestCan someone help me fix this?
source
share