Java文件(将字符串作为文件名发送)

时间:2015-01-05 18:01:22

标签: java file

我想从项目text_d.txt中的文档中获取一些信息。

现在我发送" text_d.txt"通过字符串s2。该文件已存在(text_d.txt)但输出文件s3,不显示任何内容(空)。 问题是:为什么它没有显示任何东西。我写错了吗?

dict.txt

da yes

profesor teacher

invata learns

java java

zece ten

programare programming

noteaza rates

primeste gets

student student

和text_d.txt

   Student invata programare 
java. Profesor noteaza 
student. Nero primeste zece.

文件编写代码使用此方法:

   public String getTtoD(String _wordtotranslate,String s)throws Throwable

    {
      FileInputStream _dict=new FileInputStream(s);
      BufferedReader _read=new BufferedReader(new InputStreamReader(_dict));
      String _line=_read.readLine();
      char c;
      int sem=0;
      for(int i=0;i<_wordtotranslate.length();i++)
      {
          c=_wordtotranslate.charAt(i);
          if(c>='A' && c<='Z')
              sem=1;

      }
      _wordtotranslate=_wordtotranslate.toLowerCase();
      while(_line!=null)

      {
         String [] _v=_line.split(" ");
         if(_wordtotranslate.equals(_v[1]))
         {
             if(sem==1)
                  {_v[0]=_v[0].substring(0,1).toUpperCase()+_v[0].substring(1);
                  return _v[0];
                  }

             return _v[0];
         }

         _line=_read.readLine();
      }
     _read.close();
     if(sem==1)return             _wordtotranslate=_wordtotranslate.substring(0,1).toUpperCase()+_wordtotranslate.substring(1);
     return _wordtotranslate;

    }

这是写入文件的代码:

       if(dan==1)
     {
      File f=new File(s3);
      f.createNewFile();
      FileInputStream _inputfile=new FileInputStream(s2);
      BufferedReader _readfile=new BufferedReader(new InputStreamReader(_inputfile));
      String _str=_readfile.readLine();
      FileWriter _filewrite=new FileWriter(f);
      BufferedWriter _buffwrt=new BufferedWriter(_filewrite);
      while(_str!=null)
      {
            while (_str != null) {
                String[] _vect = _str.split(" ");
                if(_vect.length>4)throw new WrongSyntax();
                int i;
                for (i = 0; i < _vect.length; i++) {
                    if (_vect[i].contains(".")) {
                         _vect[i]=removeCharAt(_vect[i],_vect[i].indexOf("."));
                        _buffwrt.write(getDtoT(_vect[i],s4) + ".");

                    }

                    else
                        _buffwrt.write(getDtoT(_vect[i],s4) + " ");
                    _buffwrt.flush();
                }
                _buffwrt.flush();
                _str =_readfile.readLine();

            }
            _buffwrt.close();
      }

0 个答案:

没有答案