except Exception, e: continue finally: if fs is not None: fs.Close() ms = None fs = None try: ms = MemoryStream() characters = Array.CreateInstance(Character, 1) characters[0] = characterList[Random(Environment.TickCount).Next( characterList.Count)] serializer = XmlSerializer(characters.GetType()) serializer.Serialize(ms, characters) ms.Seek(0, SeekOrigin.Begin) fs = FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read) buffer = ms.ToArray() fs.Write(buffer, 0, buffer.Length) fs.Flush() finally: if fs is not None: fs.Close() if ms is not None: ms.Close()
import clr # -------------------------------------------------------- # System.IOを使用したファイル書き込み clr.AddReference('System.IO') from System.IO import FileStream file = FileStream("Net.txt", 2, 2) file.Write(b'aaaaa', 0, 5) file.Close