mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 16 Jan 2012 12:59 PM |
I keep getting that error on this code (C#)
using System; using System.IO;
namespace fileWrite { public class writeClass { public static void create(string fileBody, string filePath) { string path = Path.Combine(filePath, "File.lua"); var sw = new StreamWriter(path); File.WriteAllText(path, fileBody); } } }
Can anyone help :x? It's saying that "it is being used by another process." |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2012 01:12 PM |
| It means the file is being used by another process. The error isn't something that's vague, close any other process that has "File.lua" open. And handle exceptions in code so your program doesn't terminate (hint: try-catch blocks). |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 16 Jan 2012 01:32 PM |
| Well, how is it being used by something else? |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
| |
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 16 Jan 2012 02:20 PM |
try-catch blocks.
---------- ~ pwnedu46, the unicorn ~ |
|
|
| Report Abuse |
|
|
|
| 16 Jan 2012 03:03 PM |
"Well, how is it being used by something else?"
Exactly how the error says it is: You have it open in another process. |
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
|
| 16 Jan 2012 03:05 PM |
Are you editing it with notepad? Did you forget to close an old version of that program?
~Atheist, dutch, canadian, programmer, "markuper" |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 16 Jan 2012 03:06 PM |
Here is the error I got with catch
System.IO.IOException: The process cannot access the file 'C:\Users\Laptop1\AppData\Local\Roblox\plugins\Mew903_Created_Plugin\Plugin_Script.lua' because it is being used by another process. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) at System.IO.StreamWriter.CreateFile(String path, Boolean append) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding) at System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding) at System.IO.File.WriteAllText(String path, String contents) at FileWrite.writeClass.create(String fileBody, String filePath, TextBox textBox3) in C:\Users\Laptop1\AppData\Local\Temporary Projects\Roblox Plugin Maker\FileWrite.cs:line 15
:c |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
|
| 16 Jan 2012 03:07 PM |
| And booing, I'm using Visual C# 2010 |
|
|
| Report Abuse |
|
|
LocalChum
|
  |
| Joined: 04 Mar 2011 |
| Total Posts: 6906 |
|
|
| 16 Jan 2012 04:19 PM |
| The StreamWriter opens it so that you can't use WriteAllText. Get rid of the StreamWriter to make it work. |
|
|
| Report Abuse |
|
|
mew903
|
  |
| Joined: 03 Aug 2008 |
| Total Posts: 22071 |
|
| |
|