leaningtech / cheerpj-meta

Run Java 8 applications, libraries, applets, Java Web Start, and Oracle Forms on the web without legacy plugins.
https://labs.leaningtech.com/cheerpj
468 stars 21 forks source link

java.io.FileNotFoundException ocurred when create fileInputStream #179

Closed aidscooler closed 9 months ago

aidscooler commented 9 months ago

I'm using CheerpJ in a Vue3 project.When I create a fileInputStream, java.io.FileNotFoundException ocurred. I'm sure the file is really exsist. here is my code: const pdftoword = async (file: File) => {
await cheerpjInit() const lib = await cheerpjRunLibrary("/app/Aspose.PDF/aspose-pdf-23.1.jar") try{ const FileInputStream = await lib.java.io.FileInputStream const FileOutputStream = await lib.java.io.FileOutputStream const fileStream = await new FileInputStream(file) const os = await new FileOutputStream("/test.docx") const Document = await lib.com.aspose.pdf.Document const SaveFormat = await lib.com.aspose.pdf.SaveFormat const doc = await new Document(fileStream) await doc.save(os,SaveFormat.DocX) await os.close() await doc.close() }catch(e){ const IOException = await lib.java.io.IOException if (e instanceof IOException) { console.log("I/O error:" + (await e.getMessage())) }else { console.log("Unknown error: " + (await e.getMessage())) } } } QQ截图20240127122049

alexp-sssup commented 9 months ago

/test.docx is not a valid path in the CheerpJ virtual file system. You should use /files/test.docx, since /files is the read-write persistent mount point.

For more information on CheerpJ file systems: https://labs.leaningtech.com/cheerpj3/guides/File-System-support

For these sort of small questions it's better to use Discord: https://discord.gg/X9ruPkchM5

aidscooler commented 9 months ago

I mean the exception was occured at this code: const fileStream = await new FileInputStream(file) it seems the argument file is taken as a file path,actually it is a File type argument. I'm also wondering if there is anyway to run CheerpJ locally,because some .jar file couldn't be downloaded due to network problem , see the error message below : GET https://cjrtnc.leaningtech.com/3.0rc2/8/resources.jar net::ERR_CACHE_OPERATION_NOT_SUPPORTED I've noticed this problem several times and the name of .jar file which couldn't be downloaded is diffrent everytime.