0
我在終端中有這個。當我從主目錄調用它時,沒有任何問題,它可以很好地工作。但是當我把它放到子目錄CPS3498並編譯它時,沒有錯誤。當我嘗試做java home/student/pshivam/CPS3498/encrypt
運行它給了我這個錯誤如何獲取java代碼編譯目錄
Exception in thread "main" java.lang.NoClassDefFoundError: /home/student/pshivam/CPS3498/encrypt
Caused by: java.lang.ClassNotFoundException: .home.student.pshivam.CPS3498.encrypt
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: /home/student/pshivam/CPS3498/encrypt. Program will exit
代碼如下程序。
import java.lang.ClassNotFoundException;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class encrypt {
public static void main(String[] args) throws IOException {
try {
File file = new File("/home/student/pshivam/CPS3498/letter.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line);
stringBuffer.append("\n");
}
fileReader.close();
for(int i = 0; i<stringBuffer.length(); i++){
int encrypt = 0;
encrypt = (int)stringBuffer.charAt(i);
encrypt = encrypt * 9;
stringBuffer.setCharAt(i, (char)encrypt);
File message = new File("/home/student/pshivam/CPS3498/secret.txt");
try
{
message.createNewFile();
FileWriter msgFile = new FileWriter(message);
BufferedWriter msgBuff = new BufferedWriter(msgFile);
msgBuff.write(stringBuffer.toString());
msgBuff.close();
}
finally
{
}
}
} finally{
}
}
}
這個源文件是否有軟件包? –
@TimBiegeleisen我沒有包 – Shiv
我有另一個類似於此的代碼,但只是解密 – Shiv