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 create and write a textfile in VBA

To create and write a textfile in VBA you can use the following snippet.
This should also work when using VB6.

Sample VBA

Dim fso as Object
Dim oFile as Object

Set fso = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.CreateTextFile("C:\Users\Codesnippets\Desktop\Test.txt")

oFile.WriteLine "This is a sample line!" 
oFile.Close

Set fso = Nothing
Set oFile = Nothing  

Please rate this snippet

How to read a textfile in VBA

To read a textfile in VBA you can use the following snippet.
to read a textfile line by line see How to read a textfile line by line in VBA.

Sample VBA

Function ReadTextfileComplete(ByVal strFile As String) As String
Dim hFile As Long
    hFile = FreeFile
    Open strFile For Input As #hFile
    ReadTextfileComplete = Input$(LOF(hFile), hFile)
    Close #hFile
End Function

Please rate this snippet