//public static void WriteHexDumpFromFile(string filename) //{ // try // { // File file = new File(filename); // RandomAccessFile stream = new RandomAccessFile(file, "r"); // sbyte[] bytes = new sbyte[stream.length()]; // stream.read(bytes); // stream.close(); // System.Console.WriteLine("dump of [" + file + "]"); // Console.WriteHexDump(bytes); // } // catch (Exception exc) // { // Console.WriteThrowable(exc); // } //} /// <summary> /// writes bytes to file /// </summary> /// <param name="cdata"></param> /// <param name="p"></param> public static void WriteBytes(sbyte[] cdata, string filename, bool utf8) { try { File f = new File(filename); if (f.exists()) f.delete(); RandomAccessFile stream = new RandomAccessFile(filename, "rw"); if (utf8) { stream.writeByte(0xEF); stream.writeByte(0xBB); stream.writeByte(0xBF); } stream.write(cdata); stream.close(); } catch { } }
public virtual void writePlayerData(EntityPlayer entityplayer) { try { var nbttagcompound = new NBTTagCompound(); entityplayer.writeToNBT(nbttagcompound); var file = new File(worldFile, "_tmp_.dat"); var file1 = new File(worldFile, (new StringBuilder()).append(entityplayer.username).append(".dat").toString()); CompressedStreamTools.writeGzippedCompoundToOutputStream(nbttagcompound, new FileOutputStream(file)); if (file1.exists()) { file1.delete(); } file.renameTo(file1); } catch (Exception) { logger.warning( (new StringBuilder()).append("Failed to save player data for ").append(entityplayer.username). toString()); } }
public virtual void func_22094_a(WorldInfo worldinfo) { NBTTagCompound nbttagcompound = worldinfo.func_22185_a(); var nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setTag("Data", nbttagcompound); try { var file = new File(field_22099_b, "level.dat_new"); var file1 = new File(field_22099_b, "level.dat_old"); var file2 = new File(field_22099_b, "level.dat"); CompressedStreamTools.writeGzippedCompoundToOutputStream(nbttagcompound1, new FileOutputStream(file)); if (file1.exists()) { file1.delete(); } file2.renameTo(file1); if (file2.exists()) { file2.delete(); } file.renameTo(file2); if (file.exists()) { file.delete(); } } catch (Exception exception) { exception.printStackTrace(); } }
public static void main(string[] args) { string[] strArray = args; int length = strArray.Length; for (int index = 0; index < length; ++index) { File file = new File(strArray[index]); while (file.exists()) { if (!file.delete()) { try { Thread.sleep(100L); } catch (InterruptedException ex) { } } else break; } } }