云服务器内容精选

  • 代码样例 /** * create file,write file */ private void write() throws IOException { final String content = "hi, I am bigdata. It is successful if you can see me."; FileOutStream out = null; try { AlluxioURI path = new AlluxioURI(testFilePath); out = fSystem.createFile(path); out.write(content.getBytes()); } catch (Exception e){ System.out.println("Failed to write file. Exception:" + e); } finally { close(out); } }
  • 代码样例 /** * read file * @throws java.io.IOException */ private void read() throws IOException { AlluxioURI path = new AlluxioURI(testFilePath); FileInStream in = null; try{ in = fSystem.openFile(path); byte[] buffer = new byte[1024]; int len; String content = ""; while((len = in.read(buffer)) != -1){ String bufferStr = new String(buffer,0, len); content += bufferStr; } System.out.println(content); } catch (Exception e){ System.out.println("Failed to read file. Exception:" + e); } finally { close(in); } }