我在OSX 10.10.1上使用Mac
我创建了一个名为import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Properties;
public class Autoingestion
{
public static void main(String[] paramArrayOfString)
{
int i = 0;
String str1 = null;
String str2 = "";
String str3 = null;
String str4 = null;
String str5 = null;
String str6 = null;
File localFile1 = new File(".");
try
{
String str7 = localFile1.getCanonicalPath();
str6 = paramArrayOfString[0];
localObject2 = str7 + "/" + str6;
boolean bool1 = str6.endsWith(".properties");
File localFile2 = new File((String)localObject2);
boolean bool2 = localFile2.exists();
if ((bool1) && (bool2))
{
Properties localProperties = new Properties();
localProperties.load(new FileInputStream((String)localObject2));
str3 = localProperties.getProperty("userID");
str4 = localProperties.getProperty("password");
str5 = paramArrayOfString[1];
if ((str3.isEmpty()) || (null == str3) || (null == str4) || (str4.isEmpty()))
{
System.out.println("Please check the parameters in properties file ");
return;
}
if ((paramArrayOfString.length < 5) || (paramArrayOfString.length > 6))
{
System.out.println("Please enter all the required parameters. For help, please download the latest User Guide from the Sales and Trends module in iTunes Connect.");
return;
}
i = 1;
}
else
{
if (bool1)
{
System.out.println("Property file missing");
return;
}
if ((bool2) && (!bool1))
{
System.out.println("Property File missing. Please use the properties file for user credentials");
return;
}
}
if (!bool1)
{
System.out.println("The username and password parameters have been deprecated. Please use the properties file for user credentials.");
if ((paramArrayOfString.length < 6) || (paramArrayOfString.length > 7))
{
System.out.println("Please enter all the required parameters. For help, please download the latest User Guide from the Sales and Trends module in iTunes Connect.");
return;
}
str3 = paramArrayOfString[0];
str4 = paramArrayOfString[1];
str5 = paramArrayOfString[2];
}
}
catch (Exception localException1)
{
System.out.println("Exception is =" + localException1.getMessage());
}
if ((i == 1) && (paramArrayOfString.length == 6) && (null != paramArrayOfString[5]))
{
str1 = paramArrayOfString[5];
}
else if ((i == 0) && (paramArrayOfString.length == 7) && (null != paramArrayOfString[6]))
{
str1 = paramArrayOfString[6];
}
else
{
localObject1 = Calendar.getInstance();
localObject2 = new SimpleDateFormat("yyyyMMdd");
((Calendar)localObject1).add(5, -1);
str1 = ((SimpleDateFormat)localObject2).format(((Calendar)localObject1).getTime()).toString();
}
Object localObject1 = null;
Object localObject2 = null;
try
{
str2 = "USERNAME=" + URLEncoder.encode(str3, "UTF-8");
str2 = str2 + "&PASSWORD=" + URLEncoder.encode(str4, "UTF-8");
str2 = str2 + "&VNDNUMBER=" + URLEncoder.encode(str5, "UTF-8");
if (i == 1)
{
str2 = str2 + "&TYPEOFREPORT=" + URLEncoder.encode(paramArrayOfString[2], "UTF-8");
str2 = str2 + "&DATETYPE=" + URLEncoder.encode(paramArrayOfString[3], "UTF-8");
str2 = str2 + "&REPORTTYPE=" + URLEncoder.encode(paramArrayOfString[4], "UTF-8");
str2 = str2 + "&REPORTDATE=" + URLEncoder.encode(str1, "UTF-8");
}
else
{
str2 = str2 + "&TYPEOFREPORT=" + URLEncoder.encode(paramArrayOfString[3], "UTF-8");
str2 = str2 + "&DATETYPE=" + URLEncoder.encode(paramArrayOfString[4], "UTF-8");
str2 = str2 + "&REPORTTYPE=" + URLEncoder.encode(paramArrayOfString[5], "UTF-8");
str2 = str2 + "&REPORTDATE=" + URLEncoder.encode(str1, "UTF-8");
}
}
catch (Exception localException2)
{
System.out.println("Some problem occured." + localException2);
}
try
{
localObject2 = new URL("https://reportingitc.apple.com/autoingestion.tft?");
localObject1 = (HttpURLConnection)((URL)localObject2).openConnection();
((HttpURLConnection)localObject1).setRequestMethod("POST");
((HttpURLConnection)localObject1).setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
((HttpURLConnection)localObject1).setDoOutput(true);
OutputStreamWriter localOutputStreamWriter = new OutputStreamWriter(((HttpURLConnection)localObject1).getOutputStream());
localOutputStreamWriter.write(str2);
localOutputStreamWriter.flush();
localOutputStreamWriter.close();
if (((HttpURLConnection)localObject1).getHeaderField("ERRORMSG") != null) {
System.out.println(((HttpURLConnection)localObject1).getHeaderField("ERRORMSG"));
} else if (((HttpURLConnection)localObject1).getHeaderField("filename") != null) {
getFile((HttpURLConnection)localObject1);
}
}
catch (Exception localException3)
{
System.out.println("The report you requested is not available at this time. Please try again in a few minutes.");
}
finally
{
if (localObject1 != null)
{
((HttpURLConnection)localObject1).disconnect();
localObject1 = null;
}
}
}
private static void getFile(HttpURLConnection paramHttpURLConnection)
throws IOException
{
String str = paramHttpURLConnection.getHeaderField("filename");
System.out.println(str);
int i = 0;
BufferedInputStream localBufferedInputStream = new BufferedInputStream(paramHttpURLConnection.getInputStream());
BufferedOutputStream localBufferedOutputStream = new BufferedOutputStream(new FileOutputStream(str));
byte[] arrayOfByte = new byte['Ѐ'];
while ((i = localBufferedInputStream.read(arrayOfByte)) != -1) {
localBufferedOutputStream.write(arrayOfByte, 0, i);
}
localBufferedInputStream.close();
localBufferedOutputStream.close();
System.out.println("File Downloaded Successfully ");
}
}
的文件夹,然后使用TextEdit保存了一个名为myruby
的文件。该文件说
first.rb
在终端我输入puts "Hello World"
。我使用cd myruby
来确保文件存在。
当我输入ls
时,我收到此消息:
ruby first.rb
我做错了什么?显然该文件存在,并且终端打开它,但它不能运行它?
答案 0 :(得分:7)
仔细查看错误消息:
first.rb:1:in `': uninitialized constant World” (NameError)
它抱怨的未初始化常量被命名为World”
。
我猜你的档案并没有这样说:
puts "Hello World"
我猜它说的是:
puts “Hello World”
发现差异? “
和”
与"
不同。
立即解决方案是在TextEdit中关闭智能引号(和其他自动文本转换)。长期解决方案是使用TextEdit之外的其他东西;它不适合编程。尝试像SublimeText或Atom这样专门用于编程的东西。