import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class LongPathTestMain {

    private static final String LONG_PATH_PREFIX = "\\\\?\\";

    public static void main(String[] args) {
        File file;
        BufferedWriter bufferedWriter = null;
        try {
            // String filePath = LONG_PATH_PREFIX.concat("C:/node/test/123456789123456789123456789/");
            String filePath = "C:/node/test/123456789123456789123456789/";
            System.out.println(filePath);
            file = new File(filePath);
            Files.createDirectories(Paths.get(filePath));
            final StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("a".repeat(4100));
            filePath = filePath.concat(stringBuilder.toString());
            file = new File(filePath);
            Files.createFile(file.toPath());
            /*boolean isSuccessful = file.createNewFile();
            if (!isSuccessful) {
                System.out.println("Failed");
            }*/
            System.out.println("Full path: " + file.getAbsolutePath());
            System.out.println("Full path length: " + file.getAbsolutePath().length());
            bufferedWriter = new BufferedWriter(new FileWriter(file));
            bufferedWriter.write(stringBuilder.toString());
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (bufferedWriter != null) {
                try {
                    bufferedWriter.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}