本文整理汇总了C#中File.exists方法的典型用法代码示例。如果您正苦于以下问题:C# File.exists方法的具体用法?C# File.exists怎么用?C# File.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testOneDictionary
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testOneDictionary() throws Exception
public virtual void testOneDictionary()
{
string toTest = "hu_HU.zip";
for (int i = 0; i < tests.Length; i++)
{
if (tests[i].Equals(toTest))
{
File f = new File(DICTIONARY_HOME, tests[i]);
Debug.Assert(f.exists());
using (ZipFile zip = new ZipFile(f, StandardCharsets.UTF_8))
{
ZipEntry dicEntry = zip.getEntry(tests[i + 1]);
Debug.Assert(dicEntry != null);
ZipEntry affEntry = zip.getEntry(tests[i + 2]);
Debug.Assert(affEntry != null);
using (System.IO.Stream dictionary = zip.getInputStream(dicEntry), System.IO.Stream affix = zip.getInputStream(affEntry))
{
new Dictionary(affix, dictionary);
}
}
}
}
}
示例2: test
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void test() throws Exception
public virtual void test()
{
for (int i = 0; i < tests.Length; i += 3)
{
File f = new File(DICTIONARY_HOME, tests[i]);
Debug.Assert(f.exists());
using (ZipFile zip = new ZipFile(f, StandardCharsets.UTF_8))
{
ZipEntry dicEntry = zip.getEntry(tests[i + 1]);
Debug.Assert(dicEntry != null);
ZipEntry affEntry = zip.getEntry(tests[i + 2]);
Debug.Assert(affEntry != null);
using (System.IO.Stream dictionary = zip.getInputStream(dicEntry), System.IO.Stream affix = zip.getInputStream(affEntry))
{
Dictionary dic = new Dictionary(affix, dictionary);
Console.WriteLine(tests[i] + "\t" + RamUsageEstimator.humanSizeOf(dic) + "\t(" + "words=" + RamUsageEstimator.humanSizeOf(dic.words) + ", " + "flags=" + RamUsageEstimator.humanSizeOf(dic.flagLookup) + ", " + "strips=" + RamUsageEstimator.humanSizeOf(dic.stripData) + ", " + "conditions=" + RamUsageEstimator.humanSizeOf(dic.patterns) + ", " + "affixData=" + RamUsageEstimator.humanSizeOf(dic.affixData) + ", " + "prefixes=" + RamUsageEstimator.humanSizeOf(dic.prefixes) + ", " + "suffixes=" + RamUsageEstimator.humanSizeOf(dic.suffixes) + ")");
}
}
}
}
示例3: Main
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void main(String[] args) throws Exception
public static void Main(string[] args)
{
if (args.Length < 2)
{
Console.Error.WriteLine("Usage: IndexSplitter <srcDir> -l (list the segments and their sizes)");
Console.Error.WriteLine("IndexSplitter <srcDir> <destDir> <segments>+");
Console.Error.WriteLine("IndexSplitter <srcDir> -d (delete the following segments)");
return;
}
File srcDir = new File(args[0]);
IndexSplitter @is = new IndexSplitter(srcDir);
if (!srcDir.exists())
{
throw new Exception("srcdir:" + srcDir.AbsolutePath + " doesn't exist");
}
if (args[1].Equals("-l"))
{
@is.listSegments();
}
else if (args[1].Equals("-d"))
{
IList<string> segs = new List<string>();
for (int x = 2; x < args.Length; x++)
{
segs.Add(args[x]);
}
@is.remove(segs.ToArray());
}
else
{
File targetDir = new File(args[1]);
IList<string> segs = new List<string>();
for (int x = 2; x < args.Length; x++)
{
segs.Add(args[x]);
}
@is.Split(targetDir, segs.ToArray());
}
}
示例4: extractAssets
/// <summary>
/// Extracts the media used by this sample to SD card or equivalent.
/// </summary>
private void extractAssets()
{
AssetManager assetManager = Assets;
File destDir = new File(Environment.ExternalStorageDirectory, ASSETS_SUBDIR);
if (!destDir.exists())
{
if (!destDir.mkdirs())
{
Toast.makeText(this, [email protected]_to_load_asset, Toast.LENGTH_LONG).show();
return;
}
}
foreach (string filename in ALL_ASSETS)
{
System.IO.Stream @in = null;
System.IO.Stream @out = null;
try
{
File destination = new File(destDir, filename);
if (destination.exists() == false)
{
@in = assetManager.open(filename);
@out = new System.IO.FileStream(destination, System.IO.FileMode.Create, System.IO.FileAccess.Write);
sbyte[] buffer = new sbyte[16 * 1024];
int read;
while ((read = @in.Read(buffer, 0, buffer.Length)) != -1)
{
@out.Write(buffer, 0, read);
}
}
}
catch (IOException)
{
Toast.makeText(this, [email protected]_to_load_asset, Toast.LENGTH_LONG).show();
// finish();
}
finally
{
if (@in != null)
{
try
{
@in.Close();
}
catch (IOException)
{
// Error during close, ignoring.
}
}
if (@out != null)
{
try
{
@out.Close();
}
catch (IOException)
{
// Error during close, ignoring.
}
}
}
}
}
示例5: loadSynonyms
/// <summary>
/// Load synonyms with the given <seealso cref="SynonymMap.Parser"/> class.
/// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private org.apache.lucene.analysis.synonym.SynonymMap loadSynonyms(ResourceLoader loader, String cname, boolean dedup, org.apache.lucene.analysis.Analyzer analyzer) throws java.io.IOException, java.text.ParseException
private SynonymMap loadSynonyms(ResourceLoader loader, string cname, bool dedup, Analyzer analyzer)
{
CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
SynonymMap.Parser parser;
Type clazz = loader.findClass(cname, typeof(SynonymMap.Parser));
try
{
parser = clazz.getConstructor(typeof(bool), typeof(bool), typeof(Analyzer)).newInstance(dedup, expand, analyzer);
}
catch (Exception e)
{
throw new Exception(e);
}
File synonymFile = new File(synonyms);
if (synonymFile.exists())
{
decoder.reset();
parser.parse(new InputStreamReader(loader.openResource(synonyms), decoder));
}
else
{
IList<string> files = splitFileNames(synonyms);
foreach (string file in files)
{
decoder.reset();
parser.parse(new InputStreamReader(loader.openResource(file), decoder));
}
}
return parser.build();
}
示例6: onResume
protected internal override void onResume()
{
base.onResume();
if (mInputImage != null)
{
File inputFile = new File(mInputImage);
if (!inputFile.exists())
{
mInputImage = null;
mBitmapButton.Enabled = false;
mFileButton.Enabled = false;
mInputImageView.ImageDrawable = getDrawable(R.drawable.bg_image_frame);
mOutputImageView.ImageDrawable = getDrawable(R.drawable.bg_image_frame);
}
}
}
示例7: save
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: void save(final android.media.Image image, String filename)
internal virtual void save(Image image, string filename)
{
File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).AbsolutePath + "/Camera/");
if (!dir.exists())
{
dir.mkdirs();
}
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File file = new java.io.File(dir, filename);
File file = new File(dir, filename);
outerInstance.mBackgroundHandler.post(() =>
{
ByteBuffer buffer = image.Planes[0].Buffer;
sbyte[] bytes = new sbyte[buffer.remaining()];
buffer.get(bytes);
System.IO.FileStream output = null;
try
{
output = new System.IO.FileStream(file, System.IO.FileMode.Create, System.IO.FileAccess.Write);
output.Write(bytes, 0, bytes.Length);
}
catch (IOException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
finally
{
image.close();
if (null != output)
{
try
{
output.Close();
}
catch (IOException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
}
}
MediaScannerConnection.scanFile(outerInstance, new string[]{file.AbsolutePath}, null, new OnScanCompletedListenerAnonymousInnerClassHelper(this));
runOnUiThread(() =>
{
Toast.makeTextuniquetempvar.show();
});
});
}
示例8: createNewFileTest
public void createNewFileTest()
{
File target = new File(this.tempPath,"HereIAm.file"); // TODO: Initialize to an appropriate value
if (target.exists()) target.delete();
Assert.IsFalse(target.exists());
bool created = target.createNewFile();
Assert.IsTrue(created);
target = new File(target.getAbsolutePath());
Assert.IsTrue(target.exists());
}
示例9: isFileTest
public void isFileTest()
{
File target = new File(this.tempPath); // TODO: Initialize to an appropriate value
bool expected = false; // TODO: Initialize to an appropriate value
bool actual;
actual = target.isFile();
Assert.AreEqual(expected, actual);
target = new File(this.tempPath,"Yes.file"); // TODO: Initialize to an appropriate value
target.createNewFile();
target = new File(target.getAbsolutePath()); // .net caching file status, so after create make new File instance
Assert.IsTrue(target.exists());
expected = true; // TODO: Initialize to an appropriate value
actual = target.isFile();
Assert.AreEqual(expected, actual);
target = new File(string.Empty); // TODO: Initialize to an appropriate value
expected = false; // TODO: Initialize to an appropriate value
actual = target.isFile();
Assert.AreEqual(expected, actual);
}
示例10: existsTest
public void existsTest()
{
String name = "notExists";
File target = new File(name); // TODO: Initialize to an appropriate value
bool expected = false; // TODO: Initialize to an appropriate value
bool actual = target.exists();
Assert.AreEqual(expected, actual);
target = new File(this.tempPath);
expected = true;
actual = target.exists();
Assert.AreEqual(expected, actual);
target = new File(string.Empty);
expected = false;
actual = target.exists();
Assert.AreEqual(expected, actual);
target = new File(tempPath, string.Empty);
expected = true;
actual = target.exists();
Assert.AreEqual(expected, actual);
target = new File(tempPath, name);
expected = false;
actual = target.exists();
Assert.AreEqual(expected, actual);
}
示例11: deleteTest
public void deleteTest()
{
File target = new File(tempPath,"Erease.Me"); // TODO: Initialize to an appropriate value
target.createNewFile();
Assert.IsTrue(target.exists());
bool expected = true; // TODO: Initialize to an appropriate value
bool actual = target.delete();
Assert.AreEqual(expected, actual);
}
示例12: saveBitmapPNGWithBackgroundColor
/// <summary>
/// Save PNG image with background color
/// </summary>
/// <param name="strFileName">
/// Save file path </param>
/// <param name="bitmap">
/// Input bitmap </param>
/// <param name="nQuality">
/// Jpeg quality for saving </param>
/// <param name="nBackgroundColor">
/// background color </param>
/// <returns> whether success or not </returns>
public static bool saveBitmapPNGWithBackgroundColor(string strFileName, Bitmap bitmap, int nBackgroundColor)
{
bool bSuccess1 = false;
bool bSuccess2 = false;
bool bSuccess3;
File saveFile = new File(strFileName);
if (saveFile.exists())
{
if (!saveFile.delete())
{
return false;
}
}
int nA = (nBackgroundColor >> 24) & 0xff;
// If Background color alpha is 0, Background color substitutes as white
if (nA == 0)
{
nBackgroundColor = unchecked((int)0xFFFFFFFF);
}
Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
Bitmap newBitmap = Bitmap.createBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(newBitmap);
canvas.drawColor(nBackgroundColor);
canvas.drawBitmap(bitmap, rect, rect, new Paint());
System.IO.Stream @out = null;
try
{
bSuccess1 = saveFile.createNewFile();
}
catch (IOException e1)
{
// TODO Auto-generated catch block
Console.WriteLine(e1.ToString());
Console.Write(e1.StackTrace);
}
try
{
@out = new System.IO.FileStream(saveFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);
bSuccess2 = newBitmap.compress(Bitmap.CompressFormat.PNG, 100, @out);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
try
{
if (@out != null)
{
@out.Flush();
@out.Close();
bSuccess3 = true;
}
else
{
bSuccess3 = false;
}
}
catch (IOException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
bSuccess3 = false;
}
finally
{
if (@out != null)
{
try
{
@out.Close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
}
//.........这里部分代码省略.........
示例13: save
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: void save(final android.media.Image image, String filename)
internal virtual void save(Image image, string filename)
{
File dir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).AbsolutePath + "/Camera/");
if (!dir.exists())
{
dir.mkdirs();
}
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.File file = new java.io.File(dir, filename);
File file = new File(dir, filename);
if (image.Format == ImageFormat.RAW_SENSOR)
{
SCaptureResult result = null;
try
{
result = outerInstance.mCaptureResultQueue.take();
}
catch (InterruptedException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
try
{
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final com.samsung.android.sdk.camera.SDngCreator dngCreator = new com.samsung.android.sdk.camera.SDngCreator(mCharacteristics, result);
SDngCreator dngCreator = new SDngCreator(outerInstance.mCharacteristics, result);
dngCreator.Orientation = DNG_ORIENTATION.get(outerInstance.JpegOrientation);
(new Handler(Looper.myLooper())).post(() =>
{
ByteBuffer buffer = image.Planes[0].Buffer;
sbyte[] bytes = new sbyte[buffer.remaining()];
buffer.get(bytes);
System.IO.FileStream output = null;
try
{
output = new System.IO.FileStream(file, System.IO.FileMode.Create, System.IO.FileAccess.Write);
dngCreator.writeImage(output, image);
}
catch (IOException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
finally
{
image.close();
dngCreator.close();
if (null != output)
{
try
{
output.Close();
}
catch (IOException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
}
}
MediaScannerConnection.scanFile(outerInstance, new string[]{file.AbsolutePath}, null, new OnScanCompletedListenerAnonymousInnerClassHelper(this));
runOnUiThread(() =>
{
Toast.makeTextuniquetempvar.show();
});
});
}
catch (System.ArgumentException e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
outerInstance.showAlertDialog("Fail to save DNG file.", false);
image.close();
return;
}
}
else
{
(new Handler(Looper.myLooper())).post(() =>
{
ByteBuffer buffer = image.Planes[0].Buffer;
sbyte[] bytes = new sbyte[buffer.remaining()];
buffer.get(bytes);
System.IO.FileStream output = null;
try
{
output = new System.IO.FileStream(file, System.IO.FileMode.Create, System.IO.FileAccess.Write);
output.Write(bytes, 0, bytes.Length);
}
catch (IOException e)
{
//.........这里部分代码省略.........
示例14: deleteFile
private static void deleteFile(File file)
{
if (file.exists() && !file.delete())
{
throw new IOException("Could not delete file: " + file.getCanonicalPath());
}
}
示例15: doCopyTo
private void doCopyTo(File to, object exclude, object overwrite)
{
// check exclude
if (exclude is Regex)
{
if (((Regex)exclude).matches(m_uri.toStr())) return;
}
else if (exclude is Func)
{
if (((Func)exclude).call(this) == Boolean.True) return;
}
// check for overwrite
if (to.exists())
{
if (overwrite is Boolean)
{
if (overwrite == Boolean.False) return;
}
else if (overwrite is Func)
{
if (((Func)overwrite).call(this) == Boolean.False) return;
}
else
{
throw IOErr.make("No overwrite policy for `" + to + "`").val;
}
}
// copy directory
if (isDir())
{
to.create();
List kids = list();
for (int i=0; i<kids.sz(); ++i)
{
File kid = (File)kids.get(i);
kid.doCopyTo(to.plusNameOf(kid), exclude, overwrite);
}
}
// copy file contents
else
{
OutStream @out = [email protected]();
try
{
@in().pipe(@out);
}
finally
{
@out.close();
}
}
}