小编And*_*ham的帖子

如何覆盖现有的Java文件

我想覆盖之前保存的文件,我的SaveAs代码:

public void SaveAs(){
            judul = jTextJudul.getText();
            s = area.getText();
            if(s.length()>0){//jika s terisi
                try { 
                    dialog = new FileDialog(this,"Save File As",FileDialog.SAVE);
                    dialog.setFile(judul+".txt");
                    dialog.setVisible(true);
                    path=dialog.getDirectory()+dialog.getFile();
                    FileOutputStream fos=new FileOutputStream(path);
                    System.out.println(s);
                    byte[] b=s.getBytes();
                    fos.write(b);
                    fos.close();
                    setTitle(name);
                }
                catch(Exception e){
                    JOptionPane.showMessageDialog(this,e.getMessage());
                }
            }
            else{
                JOptionPane.showMessageDialog(this,"Apa anda yakin menyimpan file kosong?");
            }
        }
Run Code Online (Sandbox Code Playgroud)

而我的保存代码(必须覆盖存在的文件)

public void Save(){
        dialog = new FileDialog(this,"Save",FileDialog.SAVE);
        file = new File(path+".txt");
        s = area.getText();
          try{
            // Create file 
            FileWriter fstream = new FileWriter(file,true);
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(s);
            //Close the …
Run Code Online (Sandbox Code Playgroud)

java filedialog awt overwrite save

6
推荐指数
1
解决办法
4万
查看次数

访问Asp Core 2 View中的Session对象

我想在视图中显示Session.那可能吗?我在我看来尝试这个

<div class="content-header col-xs-12">
   <h1>Welcome, @HttpContext.Session.GetString("userLoggedName")</h1>
</div>
Run Code Online (Sandbox Code Playgroud)

但我得到一个错误

严重级代码描述项目文件行抑制状态错误 CS0120 非静态字段,方法或属性"HttpContext.Session"需要对象引用

任何帮助,我将不胜感激.谢谢

c# asp.net-mvc razor asp.net-core asp.net-core-2.0

6
推荐指数
1
解决办法
2453
查看次数