Dosya sistemindeki kaynaklarla (dosyalar) çalışmak için Spring'in Resource soyutlamasını kullanıyorum. Kaynaklardan biri, JAR dosyasının içindeki bir dosyadır. Aşağıdaki koda göre, her şey yolunda, ama sonra bir File
almak Dosya JAR
templateResource.getFile();
için Resource
dönüştürmeye çalıştığınızda özel durum almak referans Bu noktada
ResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();
// The path to the resource from the root of the JAR file
Resource fileInJar = resourcePatternResolver.getResources("/META-INF/foo/file.txt");
templateResource.exists(); // returns true
templateResource.isReadable(); // returns true
geçerlidir görünür bir JAR dosyası içinde var olan bir Resource
bir File
başvuru almak için doğru yolu
java.io.FileNotFoundException: class path resource [META-INF/foo/file.txt] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/D:/m2repo/uic-3.2.6-0.jar!/META-INF/foo/file.txt
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:198)
at org.springframework.core.io.ClassPathResource.getFile(ClassPathResource.java:174)
nedir? Onu okumak istiyorsan
bu bana bir InputStream verecektir ama ne gerçekten istiyorum o 'Dosya' ne yapacak Dosya –
bağlıdır: (aşağıda Groovy yazılır)? – Bozho
Bir Dosyaya –