Top 10 reads of July 2014

these are the top 10 reads of July 2014.

  • How to rename a file or folder in Java
  • How to delete a folder in Ruby
  • How to process all files in a directory in Python
  • How to read a file to string in Java
  • How to calculate PercentOf in PHP
  • How to get the char code in C
  • How to rename a file or folder in Ruby
  • How to count the DOM loading time in Javascript
  • How to scroll to the end of a TreeView in C# and VB.NET
  • How to set the start location of FolderBrowserDialog
  • thanks to all visitors, bookmark us, share us, talk about us, Follow us!, Like us! let’s grow bigger!

    Please rate this snippet

    How to read a file to string in Java

    To read a file to string in Java you can use the following snippet.

    Sample Java

    public static string readFileToString(FileInputStream _fileInputStream)
    {
    	try {  
    		DataInputStream dataInputStream = new DataInputStream (_fileInputStream);  
    		byte[] Bytes = new byte[dataInputStream.available ()];  
    		dataInputStream.readFully (Bytes);  
    		dataInputStream.close ();  
    		String result = new String (Bytes, 0, Bytes.length, "Cp850");  
    		return result;  
    	}  
    	catch (Exception e) {  
    		e.printStackTrace();  
    		return "";
    	} 
    }
    

    Please rate this snippet

    How to check if a file exists in C++

    To check if a file exists in C++ you can use the following snippet.

    Sample C++

    #include <sys/stat.h>
    
    inline bool fileExists (const std::string& fileName) {
    	struct stat buff;   
    	return (stat (fileName.c_str(), &buff) == 0); 
    }
    

    Please rate this snippet

    How to read a embedded resource image in C# and VB.NET

    To read a embedded resource image in C# and VB.NET you can use the following snippet.

    Sample C#

    public static Image ReadEmbeddedRessourceImage(Assembly assembly, string searchPattern)
    {
    	var resourceName = assembly.GetManifestResourceNames().FirstOrDefault(x => x.Contains(searchPattern));
    	using (var stream = assembly.GetManifestResourceStream(resourceName))
    	{
    		if (stream != null) return Image.FromStream(stream);
    	}
    	return null;
    }
    

    Sample VB.NET

    Public Shared Function ReadEmbeddedRessourceImage(assembly As Assembly, searchPattern As String) As Image
    	Dim resourceName = assembly.GetManifestResourceNames().FirstOrDefault(Function(x) x.Contains(searchPattern))
    	Using stream = assembly.GetManifestResourceStream(resourceName)
    		If stream IsNot Nothing Then
    			Return Image.FromStream(stream)
    		End If
    	End Using
    	Return Nothing
    End Function
    

    Please rate this snippet

    How to set the start location of FolderBrowserDialog in C# and VB.NET

    To set the start location of FolderBrowserDialog in C# and VB.NET you can use the following snippet.
    To do so, simply set the SelectedPath Value to the path you want.

    Sample C#

    MyFolderBrowserDialog.SelectedPath = @"C:\Test";
    

    Sample VB.NET

    MyFolderBrowserDialog.SelectedPath = "C:\Test"
    

    Please rate this snippet