Nosuchfileexception Error on java while running and trying to load data in Cassandra

Viewed 52

I keep getting this error, the path has been specified in yml and even in the console it is going to the relative path but not reading the file or finding it, how can I get past this ? I have attached the picture and below is the code in my main method. Any input is deeply appreciated. Thanks!

@SpringBootApplication
@EnableConfigurationProperties(DataStaxAstraProperties.class)
public class BookAppApplication {

    @Autowired AuthorRepostories authorRepostories;
    
    @Value("${datadump.location.author}")
    private String authorDumpsLocation;
    
    @Value("${datadump.location.works}")
    private String authorWorksLocation;
    
    public static void main(String[] args) {
        SpringApplication.run(BookAppApplication.class, args);
    }
    
    private void initAuthors() {
        Path path = Paths.get(authorDumpsLocation);
        System.out.println(path.toAbsolutePath());
        try(Stream<String> lines = Files.lines(path)){
            lines.forEach(line->{
                String jsonStr = line.substring(line.indexOf("{"));
                try {
                    JSONObject jsonObject = new JSONObject(jsonStr);
                    Author author = new Author();
                    author.setName(jsonObject.optString("name"));
                    author.setPersonalName(jsonObject.optString("personal_name"));
                    author.setId(jsonObject.optString("key").replace("/authors/",""));
                    
                    System.out.println("Saving author" + author.getName() + "....");
                    authorRepostories.save(author);
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    private void initWorks() {
        
    }
    
    @PostConstruct
    public void start() {
        initAuthors();
        initWorks();
    }

    @Bean
    public CqlSessionBuilderCustomizer sessionBuilderCustomizer(DataStaxAstraProperties astraProperties) {
        Path bundle = astraProperties.getSecureConnectBundle().toPath();
        return builder -> builder.withCloudSecureConnectBundle(bundle);
    }

}
1 Answers

found the issue. Had to do with access rights. Java couldn't access the files because it was secured after changing the property of a file, it worked.

Related