eclipse怎样导入txt文件
//下面是代码
import java.io.*;
import java.util.*;
public class Decrypts {
public static void main (String [] args) {
Scanner keyboard = new Scanner (System.in);
String fileName = new String ("Lab6-2.txt");
try {
FileReader in = new FileReader (fileName);
char[] inText = new char[5000];
int length = in.read(inText);
System.out.println ("Enter the encryption key: " + length);
int key = keyboard.nextInt();
int pass = 1;
int index = 0;
int newIndex = 0;
char [] decryptedText = new char[length];
while (pass <= key) {
while (newIndex < length) {
decryptedText[newIndex] = inText[index];
index ++;
newIndex = newIndex + key;
}
newIndex = pass;
pass ++;
}
String text = new String (decryptedText);
System.out.println ("The new text is : " + text);
in.close();
}
catch (FileNotFoundException e) {
System.out.println ("Could not open file...." + fileName + " exiting" );
System.exit(0);
}
catch (IOException e) {
System.out.println ("Could not open file...." + fileName + " exiting" );
System.exit(0);
}毕业论文
}
}
/*那个文件里面是这些字: Ntel oihyoh lmc de!wef eot ! ognmhop!itro eefasi ot r madotatt ,我是直接把文件拽到包里面的(就是Decrypts这个class的下面,在eclipse里面可以打开,但是一运行这个程序就显示打不开文件)!!菜鸟一名,求救啊~~
这样不写路径,默认是去根目录下去找的,不是包里面 如果不改代码的情况下,文件需要和class文件放在同一目录。