If you need to access a resource file inside the jar package in the jar, you can get the file contents using Class.getresourceasstream (file path).
Assuming the file path is Project/src/com/zh/resource, code is as follows:
ImportJava.io.BufferedReader;Importjava.io.IOException;ImportJava.io.InputStream;ImportJava.io.InputStreamReader;Importjava.io.UnsupportedEncodingException; Public classTest { Public Static voidMain (string[] args){stringbuffer Filestrbuffer= LoadFile ("/com/zh/resource/test.txt"); if(filestrbuffer!=NULL) {System.out.print (filestrbuffer); } } /*** Load the specified file. * * @returnThe buffer to store file content. */ Private Staticstringbuffer loadFile (String file) {StringBuffer buffer=NewStringBuffer (); InputStream is= Test.class. getResourceAsStream (file); BufferedReader reader; Try{Reader=NewBufferedReader (NewInputStreamReader (IS, "Utf-8")); String tempstring=NULL; while((tempstring = Reader.readline ())! =NULL) {buffer.append (tempstring); } } Catch(unsupportedencodingexception e) {buffer=NULL; } Catch(IOException e) {buffer=NULL; } finally { Try{is.close (); } Catch(IOException e) {}}returnbuffer;}}
Results:
Xxxxx{0}xxxxx{1}xxxxxxxx{2}xxxxxx
How to access the jar package internal resource files