0

So I have this program and I would want to have Java figure out the username by itself.

import java.io.*;
import java.nio.file.Files;

  public class Demo {
    public static void main(String[] args) throws IOException {
      File file = new File("/Users/angel/Desktop");
      String[] files = file.list();
       for (String string : files){
        for (int i = 0; i < files.length; i++) {
            if(String.valueOf(string).contains(".png")){
                File sourceFile = new File("/Users/angel/Desktop/" + string);
                File destinationFile = new 
                File("/Users/angel/Desktop/Screenshots/Screenshot" + string );
                Files.move(sourceFile.toPath(), destinationFile.toPath());
                string = "";
          }
        }
      }
    }
  }
JScode
  • 11
  • 3
  • Does this answer your question? [Recommended way to get hostname in Java](https://stackoverflow.com/questions/7348711/recommended-way-to-get-hostname-in-java) – Jeff Holt May 06 '21 at 15:15
  • "Computer Name" and "User Name" are not the same things. – PM 77-1 May 06 '21 at 15:15

0 Answers0