用Java打印外部文件中的文本

时间:2017-01-17 17:34:01

标签: java

我正在尝试使用该文件中的一行文本创建外部文件,然后在Java程序中打印该行文本。我试过了;但是,我遇到了麻烦。我的代码没有抛出任何错误,它只是无法正常工作。

........
     private String SecretKey = "0123456789abcdef";**//Read the Simcard serial number and use the first 16 numbers as a SecretKey**

       public MCrypt()
        {
            ivspec = new IvParameterSpec(iv.getBytes());

            keyspec = new SecretKeySpec(SecretKey.getBytes(), "AES");

           ................

1 个答案:

答案 0 :(得分:1)

您的代码存在的问题是,尽管您在class Position { public: Position(void) { std::cout<<"defualt constructor\n"; } Position(unsigned int row,unsigned int col) { std::cout<<"two Arguments constructor\n"; row_index = row; col_index = col; } private: unsigned int row_index; unsigned int col_index; }; class Tool { public: Tool(char Team,unsigned int row,unsigned int col) { pos = Position(row,col); team = Team; } std::string To_string() { std::string str = "team: "; str+= team; str+= " pos: "; str+= pos.To_string(); return str; } char Get_team() { return team; } private: Position pos; char team; // A or B }; int main(void) { Tool t = Tool('A',1,3); return 0; } 中获得了filename,但是您没有将文件名称设为writeFile(),而是使用filename制作文件。在您的filename.txt中,您正在阅读尚未创建的文件readFile(),但filename将创建一个空文件,但文件不存在。现在你正在读一个空文件。将以下代码放在new file(filename)

writeFile()
  

如需额外注意,请尝试不要使用try{ FileWriter fw=new FileWriter(filename); for (String words : arrayToWrite) { fw.write(words + "\n"); } fw.close(); }catch(Exception e){ System.out.println(e); } PrintWriter,因为他们不会因为错误而导致您出现问题。

相关问题