Information AboutMachine-independent |
| CATEGORIES ABOUT MACHINE-INDEPENDENT | |
| computer programming | |
|
Any well-written Java or .NET application could be machine-independent because these platforms run on Virtual Machine s on top of the real computer. The real machine-dependent part is the virtual machine, so this is the (usually little compared to the Class Libraries ) chunk of code that needs to be Ported . To be machine-independent, the application also must not use any machine or platform-specific resources available. Examples of platform specific features are .NET P/Invoke and Java Native Interface , both of which allow the direct use of native libraries. This is an example of a machine-independent and "./data.xml" in Linux (it also prints the resulting path). using System; using System.IO; namespace Test { class TestApp { public static void Main(string {Link without Title} args) { string filePath = "." + Path.DirectorySeparatorChar + "data.xml"; Console.WriteLine("The file path is: {0}", filePath); using(Stream fileData = File.Open()) { // Do anything with the file (for example, process it using System.Xml) // and don't worry about closing the stream because the using statesment // will do it for you (although you could use try-catch-finally) } } } } |
|
|