Warning: include_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /home/users/2/moriya-h5/web/confrage/java/io/write_file/write_file.html on line 2

Warning: include_once(http://www.confrage.com/bin/header.php): failed to open stream: no suitable wrapper could be found in /home/users/2/moriya-h5/web/confrage/java/io/write_file/write_file.html on line 2

Warning: include_once(): Failed opening 'http://www.confrage.com/bin/header.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/io/write_file/write_file.html on line 2
ファイルに書き込む | Java | 株式会社CONFRAGE
Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/io/write_file/write_file.html on line 17

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/menu.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/io/write_file/write_file.html on line 17
write()メソッド
java.io.BufferedWriterクラスのwrite()メソッドでファイルに書き込みを行うことが出来ます。
ファイルが存在しない場合、ファイルを新規作成します。
以下、例です。

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class Test{
    public static void main(String[] args) {    
        FileOutputStream    fos            = null;
        BufferedWriter        writeFile    = null;
        try {
            fos            = new FileOutputStream("c:¥¥test1¥¥test2¥¥kekka.txt");
            writeFile    = new BufferedWriter(new OutputStreamWriter(fos,"Shift_JIS"));
        } 
        catch(Exception e) {
            e.printStackTrace();
        }
        
        try {
            writeFile.write("test");
            writeFile.newLine();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            try {
                writeFile.close();
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
これでc:¥test1¥test2¥kekak.txtが作成され、中身にtestと書いたファイルが作成されます。
BufferedWriterのclose()メソッドを先に呼び出さないと、java.io.IOExceptionエラーとなります。

Back to top

Information

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/io/write_file/write_file.html on line 93

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/side_bar.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/io/write_file/write_file.html on line 93

Warning: include_once(/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php): failed to open stream: No such file or directory in /home/users/2/moriya-h5/web/confrage/java/io/write_file/write_file.html on line 102

Warning: include_once(): Failed opening '/home/sites/heteml/users/m/o/r/moriya-h5/web/confrage/bin/seo.php' for inclusion (include_path='.:/usr/local/php/5.6/lib/php') in /home/users/2/moriya-h5/web/confrage/java/io/write_file/write_file.html on line 102